Skip to content

Instantly share code, notes, and snippets.

@kingjr
Created June 20, 2015 12:33
Show Gist options
  • Select an option

  • Save kingjr/577cb5e0f3b4a044d2a8 to your computer and use it in GitHub Desktop.

Select an option

Save kingjr/577cb5e0f3b4a044d2a8 to your computer and use it in GitHub Desktop.
Share color limits across axes
def share_clim(axes, clim=None):
"""Share clim across multiple axes
Parameters
----------
axes : plt.axes
clim : np.array | list, shape(2,), optional
Defaults is min and max across axes.clim.
"""
# Find min max of clims
if clim is None:
clim = list()
for ax in axes:
for im in ax.get_images():
clim += np.array(im.get_clim()).flatten().tolist()
clim = [np.min(clim), np.max(clim)]
# apply common clim
for ax in axes:
for im in ax.get_images():
im.set_clim(clim)
plt.draw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment