-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Open
Labels
Description
Bug summary
When creating a colorbar using a ScalarMappable with the NoNorm normalization and a discrete colormap (e.g., viridis with a fixed number of colors), the ticks returned by the colorbar’s get_ticks() method do not align with the visually displayed tick positions. This will cause cbar.set_ticks(cbar.get_ticks()) to change the ticks.
Code for reproduction
import matplotlib.pyplot as plt
from matplotlib import cm, colors
data = [1, 2, 3, 4, 5]
fig, ax = plt.subplots()
cbar = fig.colorbar(cm.ScalarMappable(norm=colors.NoNorm(), cmap=plt.get_cmap("viridis", len(data))), ax=ax)
print(cbar.get_ticks())
cbar.set_ticks(cbar.get_ticks()) # this unexpectedly changes the ticksActual outcome
[0. 1. 2. 3. 4. 5.]
Expected outcome
[0. 1. 2. 3. 4.]
Additional information
No response
Operating system
No response
Matplotlib Version
3.10.8
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None
Reactions are currently unavailable