【发布时间】:2018-01-19 06:22:03
【问题描述】:
我正在尝试使用滑块以交互方式更改图像的内容(例如,应用具有不同内核大小的中值操作)。
虽然如果我只显示一个结果图像(参见注释行),这很有效,但在使用 subplot 函数时会遇到麻烦,因为图像不会得到更新。
我错过了什么?
%matplotlib inline
from ipywidgets import interact, widgets
import matplotlib.pyplot as plt
import warnings
from skimage.morphology import disk
from skimage.filters import rank
from skimage.color import rgb2gray
import skimage.data
def f(Median_Size):
selem = disk(int(Median_Size))
with warnings.catch_warnings():
warnings.simplefilter("ignore")
img_median = rank.median(img_gray, selem=selem)
ax_neu.imshow(img_median, cmap="gray")
fig.canvas.draw()
#plt.imshow(img_median, cmap="gray") #This would work
#plt.show()
image = skimage.data.camera() #plt.imread("Test.png")
img_gray = rgb2gray(image)
fig = plt.figure(figsize=(6, 4))
ax_orig = fig.add_subplot(121)
ax_neu = fig.add_subplot(122)
ax_orig.imshow(img_gray, cmap="gray")
ax_neu.imshow(img_gray, cmap="gray")
interact(f, Median_Size=widgets.IntSlider(min=1,max=21,step=2,value=1))
【问题讨论】:
-
我不明白你的问题。据我所知,您的代码运行良好(使用
plt.imread()而不是skimage.data.camera())。包括关于子图的部分。您能否提供有关您遇到的问题的更多信息? -
我可以使用 jupyter notebook 4.4.1 和 python 2.7 和 matplotlib 2.1 100% 地重现这个问题。 @DizietAsahi 你用的是什么版本?
-
有趣。我正在使用 matplotlib:2.0.2,jupyter:4.3.0,python:3.6.1
-
哦,我应该指出我使用的是
%matplotlib notebook而不是inline,如果这样会有所不同(我在使用inline时没有得到任何形式的交互) -
@DizietAsahi 是的,这很重要。使用
%matplotlib notebook确实是一种可能的解决方案。
标签: python matplotlib ipython jupyter-notebook