Open
Description
Bug report
Bug summary
Plotting without colorbar gives different colors than plotting with one if all plotted values are equal. While this might be expected behaviour, I find it a bit strange. Plotting colorbar alongside the plot should only show the legend to what is plotted, not change the plot itself, I would say. We ran into this recently with geopandas geopandas/geopandas#1163 . Is this the intended behaviour of matplotlib or is it something which should be changed?
Code for reproduction
Without:
sc = plt.scatter(range(3), range(3), c=[1, 1, 1], cmap='viridis')
With:
sc = plt.scatter(range(3), range(3), c=[1, 1, 1], cmap='viridis')
plt.colorbar(sc)
Actual outcome
Expected outcome
I would expect colors to be the same in both plots above.
Matplotlib version
- Operating system: macOS
- Matplotlib version: 3.1.1
- Matplotlib backend (
print(matplotlib.get_backend())
): module://ipykernel.pylab.backend_inline - Python version: 3.7.3
- Jupyter version (if applicable): 1.0.0
- Other libraries: