Mastiff
Mastiff

Reputation: 2240

In matplotlib imshow() how can I change the color axis range on an existing plot?

When making a plot to start with I can use:

fig, ax = plt.subplots() 
h = ax.imshow(X, vmin=mn, vmax=mx)

Once the plot is up, can I change my mind and make vmin and vmax something different?

Upvotes: 0

Views: 796

Answers (2)

Mastiff
Mastiff

Reputation: 2240

This also does the trick:

h.set_clim([mn, mx])

And to reset to "auto":

h.set_norm(None)

Upvotes: 0

Diziet Asahi
Diziet Asahi

Reputation: 40707

You can change the normalization of the image using set_norm() and passing a Normalize object:

norm = matplotlib.colors.Normalize(vmin=0, vmax=1)
h.set_norm(norm)

Upvotes: 2

Related Questions