I have virtually no experience with python, but I am trying to create a simple script which loads an image and uses the slider widget to adjust the minimum and maximum of the colorbar, and redraws the image data accordingly.
I am trying to follow this example: http://matplotlib.sourceforge.net/examples/widgets/slider_demo.html. I have tried to just change the plot command to imshow, and to use the slider values to set the clim of my image. However I get the following error message, from the call 'im1,=ax.imshow' (on line 12 in the code below):
'AxesImage' object is not iterable
I don't understand what this call does, but apparently it can not be used with imshow(). If I remove the comma in that call, I get no errors, but the image does not update when the sliders are changed. Does anyone have an alternative solution, or an explanation of why this does not work? Any help would be appreciated, thank you.
My code is as follows:
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()