我几乎没有python的经验,但我试图创建一个简单的脚本加载图像并使用滑块小部件来调整最小和最大的颜色条,并重绘相应的图像数据。使用matplotlib滑块小部件来改变图像上升
我正在尝试关注此示例:http://matplotlib.sourceforge.net/examples/widgets/slider_demo.html。我试图改变阴谋命令imshow,并使用滑块值设置我的形象攀登。不过,我得到以下错误消息,从呼叫“IM1,= ax.imshow”(第12行下面的代码):
“AxesImage”对象不是可迭代
我不明白是什么这个调用的确如此,但显然它不能与imshow()一起使用。如果我在该调用中删除了逗号,则不会出现错误,但当滑块发生更改时,图像不会更新。有没有人有另一种解决方案,或解释为什么这不起作用?任何帮助将不胜感激,谢谢。
我的代码如下:
from pylab import *
from matplotlib.widgets import Slider, Button, RadioButtons
import matplotlib.pyplot as plt
import numpy as np
close('all')
ax = subplot(111)
subplots_adjust(left=0.25, bottom=0.25)
min0 = 0
max0 = 25000
im=np.loadtxt('im.txt')
im1,=ax.imshow(im)
colorbar()
axcolor = 'lightgoldenrodyellow'
axmin = axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)
axmax = axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)
smin = Slider(axmin, 'Min', 0, 30000, valinit=min0)
smax = Slider(axmax, 'Max', 0, 30000, valinit=max0)
def update(val):
im1.set_clim=(smin.val,smax.val)
draw()
smin.on_changed(update)
smax.on_changed(update)
show()