Basically, you had a lot of syntax issues.
For example, you tried to unpack a single value ( im1,=ax.imshow(im)
) by specifying the TypeError
that you mentioned in your question (as it should be). You also set the function to the value when you wanted to name it: ( im1.set_clim=(smin.val,smax.val)
).
Also, I removed from pylab import *
from your example. This is normal for interactive use, but please, please do not use it for actual code. It's hard to tell where the functions you are calling come from (and the pylab namespace, in particular, is huge in design, it should only be used for interactive use or quick one-time scripts.)
Here is a working example (using random data):
import matplotlib.pyplot as plt import numpy as np from matplotlib.widgets import Slider, Button, RadioButtons fig = plt.figure() ax = fig.add_subplot(111) fig.subplots_adjust(left=0.25, bottom=0.25) min0 = 0 max0 = 25000 im = max0 * np.random.random((10,10)) im1 = ax.imshow(im) fig.colorbar(im1) axcolor = 'lightgoldenrodyellow' axmin = fig.add_axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor) axmax = fig.add_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]) fig.canvas.draw() smin.on_changed(update) smax.on_changed(update) plt.show()