vmin and vmax in hist2d

Viewed 693

I am plotting some data in python with hist2d. For the normalization of the color scale I am using the parameter

norm=matplotlib.colors.LogNorm().

How could I get (a posteriori) the values vmin and vmax that matplotlib assigns to this plot? I want matplotlib to choose them (the range is normally well chosen), and then get them and apply exactly those values to a second plot I.e., I would use:

norm=matplotlib.colors.LogNorm(vmin=vmin1, vmax=vmax1)
2 Answers

You probably should provide a more detailed example. Anyhow, the following might do the trick:

import matplotlib.pyplot as plt
hist = plt.hist2d(x, y)
vmin,vmax = hist[-1].get_clim()

Safest is probably to get the norm from the artist returned by hist2d

_, _, _, im = matplotlib.hist2d(...)
norm2 = matplotlib.colors.LogNorm(vmin=im.norm.vmin, vmax=im.norm.vmax)
Related