8000 [Bug]: Colormap + NoNorm only plots one color under `matplotlib` 3.5.0 · Issue #21870 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[Bug]: Colormap + NoNorm only plots one color under matplotlib 3.5.0 #21870
Closed
@dominiquesydow

Description

@dominiquesydow

Bug summary

My aim is to plot a colormap with e.g. 5 discrete colors (with 5 ticks centered per color).

Under matplotlib 3.4.3, I got this working with the code snippet below using NoNorm; under 3.5.0, only one color is plotted.

Is this a bug - or is my setup incorrect/unidiomatic and worked only by chance before?

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib import cm, colors

data = [1, 2, 3, 4, 5]

fig, ax = plt.subplots(figsize=(6, 1))
fig.subplots_adjust(bottom=0.5)

norm = colors.NoNorm(vmin=min(data), vmax=max(data))
cmap = cm.get_cmap("viridis", len(data))
cbar = fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), cax=ax, orientation="horizontal")
print(cbar.get_ticks())

Actual outcome

image

This is the output under matplotlib 3.5.0.

Expected outcome

image

This was the output under matplotlib 3.4.3.

Additional information

No response

Operating system

Ubuntu

Matplotlib Version

3.5.0

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

Python 3.9.7

Jupyter version

3.2.4

Installation

conda

545A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0