Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: Colormap + NoNorm only plots one color under matplotlib 3.5.0 #21870

Copy link
Copy link
Closed
@dominiquesydow

Description

@dominiquesydow
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.