日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python画图fig.show()一闪而过的解决方法

發(fā)布時間:2025/4/5 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python画图fig.show()一闪而过的解决方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

文章目錄

      • 遇到的問題
      • 解決方法
        • 做法
        • 解釋
      • 參考

遇到的問題

python版本3.8.8

在測試scipy.signal.correlate2d函數(shù)的時候,跑官網(wǎng)的demo,結果繪圖是一閃而過。函數(shù)鏈接:https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.correlate2d.html#scipy.signal.correlate2d

測試代碼

Use 2D cross-correlation to find the location of a template in a noisy image:
用2D 互相關在噪聲圖像中找到模板位置

from scipy import signal from scipy import misc import numpy as np import matplotlib.pyplot as plt from skimage import ioface = misc.face(gray=True) - misc.face(gray=True).mean() template = np.copy(face[300:365, 670:750]) # right eye template -= template.mean() face = face + np.random.randn(*face.shape) * 50 # add noise corr = signal.correlate2d(face, template, boundary='symm', mode='same') y, x = np.unravel_index(np.argmax(corr), corr.shape) # find the matchfig, (ax_orig, ax_template, ax_corr) = plt.subplots(3, 1,figsize=(6, 15)) ax_orig.imshow(face, cmap='gray') ax_orig.set_title('Original') ax_orig.set_axis_off() ax_template.imshow(template, cmap='gray') ax_template.set_title('Template') ax_template.set_axis_off() ax_corr.imshow(corr, cmap='gray') ax_corr.set_title('Cross-correlation') ax_corr.set_axis_off() ax_orig.plot(x, y, 'ro') fig.show()

解決方法

做法

法一:在fig.show()后面加上一句:

input()

這樣需要輸入回車才會結束。

法二:
棄用最后的fig.show(),改用:

plt.show()

上述兩種方法都可以解決畫圖一閃而過的問題。
得到了官網(wǎng)相同的圖:

解釋


對上面的老哥表示感謝,詳見參考1.

其實fig.show()可以用于IPython。在IPython環(huán)境下,調用plt.show()是不能顯示出繪制的圖像的,但是調用fig.show()就可以顯示出圖像。

詳見參考2

參考

[1]https://github.com/matplotlib/matplotlib/issues/13101
[2]https://eliasyin.com/2020/03/15/fig-show-%E4%B8%8E-plt-show/

總結

以上是生活随笔為你收集整理的python画图fig.show()一闪而过的解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。