If you didn't keep the returned image object, you can use pylab.gci to get the current ScalarMappable (i.e. whatever the current colorbar would be based on).
From there, you just want the get_clim method of the ScalarMappable object.
So, you could do:
vmin, vmax = plt.gci().get_clim()
Answer from Joe Kington on Stack OverflowIf you didn't keep the returned image object, you can use pylab.gci to get the current ScalarMappable (i.e. whatever the current colorbar would be based on).
From there, you just want the get_clim method of the ScalarMappable object.
So, you could do:
vmin, vmax = plt.gci().get_clim()
Found a 2006 mailing list conversation showing me the way:
im = pylab.imshow(arr)
pylab.clim(im.norm.vmax - numpy.array([0.5, 0]))
Arg. It's always the last thing you try:
quadmesh.set_clim(vmin=0, vmax=15)
works.
Matplotlib 1.3.1 - It looks like the colorbar ticks are only drawn when the colorbar is instanced. Changing the colorbar limits (set_clim) does not cause the ticks to be re-drawn.
The solution I found was to re-instance the colorbar in the same axes entry as the original colorbar. In this case, axes[1] was the original colorbar. Added a new instance of the colorbar with this designated with the cax= (child axes) kwarg.
# Reset the Z-axis limits
print "resetting Z-axis plot limits", self.zmin, self.zmax
self.cbar = self.fig.colorbar(CS1, cax=self.fig.axes[1]) # added
self.cbar.set_clim(self.zmin, self.zmax)
self.cbar.draw_all()