Closed
Description
Bug summary
colors.PowerNorm
ignores the (in this case) vmin
values, and the resulting colorbar seems to b incorrect.
Code for reproduction
import matplotlib.pyplot as pl
import matplotlib.colors as colors
import numpy as np
data = np.random.random(100*100).reshape(100,100) * 600 + 398
pl.figure()
pl.imshow(data, cmap=pl.cm.terrain, norm=colors.PowerNorm(gamma=0.2, vmin=398, vmax=1000))
pl.colorbar()
Actual outcome
It seems that vmin
is changed to some pretty number (in this case 300), but as a result, the colorbar seems to be incorrect. In the screenshot, my mouse is hoovering over the blue data point, which has a value of 398.062 (see value in top right corner of window). However, corresponding values in the colorbar are greenish, while blue colors correspond to much lower numbers.
Expected outcome
I would expect matplotlib to respect the vmin
and vmax
values that I set in colors.PowerNorm
.
You can best see the correct outcome if you manually set vmin
at the value that matplotlib chooses:
import matplotlib.pyplot as pl
import matplotlib.colors as colors
import numpy as np
data = np.random.random(100*100).reshape(100,100) * 600 + 398
pl.figure()
pl.subplot(121)
pl.imshow(data, cmap=pl.cm.terrain, norm=colors.PowerNorm(gamma=0.2, vmin=398, vmax=1000))
cb=pl.colorbar()
pl.subplot(122)
pl.imshow(data, cmap=pl.cm.terrain, norm=colors.PowerNorm(gamma=0.2, vmin=300, vmax=1000))
cb=pl.colorbar()
Additional information
No response
Operating system
Manjaro Linux
Matplotlib Version
3.6.2
Matplotlib Backend
Qt5Agg
Python version
3.10.9
Jupyter version
None
Installation
pip