Skip to content

Inconsistent plot with and without colorbar #15566

Open
@martinfleis

Description

@martinfleis

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

67638048-9a7cb800-f8d8-11e9-9584-c15ba7e78c20
67638210-f3008500-f8d9-11e9-9164-da640b7180fc

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:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions