You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
frommatplotlibimportcolorsimportmatplotlib.pyplotaspltimportnumpyasnpnp.random.seed(19680801)
Nr=3Nc=2cmap="cool"fig, axs=plt.subplots(Nr, Nc)
fig.suptitle('Multiple images')
images= []
foriinrange(Nr):
forjinrange(Nc):
# Generate data with a range that varies from one plot to the next.data= ((1+i+j) /10) *np.random.rand(10, 20) *1e-6images.append(axs[i, j].imshow(data, cmap=cmap))
axs[i, j].label_outer()
# Find the min and max of all colors for use in setting the color scale.vmin=min(image.get_array().min() forimageinimages)
vmax=max(image.get_array().max() forimageinimages)
norm=colors.Normalize(vmin=vmin, vmax=vmax)
foriminimages:
im.set_norm(norm)
fig.colorbar(images[0], ax=axs, orientation='horizontal', fraction=.1)
# Make images respond to changes in the norm of other images (e.g. via the# "edit axis, curves and images parameters" GUI on Qt), but be careful not to# recurse infinitely!defupdate(changed_image):
foriminimages:
if (changed_image.get_cmap() !=im.get_cmap()
orchanged_image.get_clim() !=im.get_clim()):
im.set_cmap(changed_image.get_cmap())
im.set_clim(changed_image.get_clim())
foriminimages:
im.callbacksSM.connect('changed', update)
images[1].set_clim(1e-9, 2e-8)
fig.savefig('ax1_bad.png')
images[0].set_clim(1e-9, 2e-8)
fig.savefig('ax0_good.png')
This is because the colorbar is listening to the "changed" event on images[0].callbacksSM, but that event is triggered when the image is directly manipulated (im.set_clim, etc.), but here they are not because it's the underlying norm object which is shared (and hence the "update" callback never fires because the clims on the image change directly via the norm object!).
Bug report
Bug summary
In the multi_image example, the colorbar is responding correctly to
set_clim
only when called on the image to which the colorbar is directly attached.Code for reproduction
This is just the example, https://matplotlib.org/gallery/images_contours_and_fields/multi_image.html, with manipulation of the clim at the bottom.
Actual outcome
ax1_bad.png:
Expected outcome
ax0_good.png:
Matplotlib version
print(matplotlib.get_backend())
): MacOSX, aggThe text was updated successfully, but these errors were encountered: