matplotlib / matplotlib/matplotlib

Colormaps are not matching with reference pngs

Open
#20,459 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: color/color & colormaps
Dominant language
Python
Stars
23.2k
Forks
8.5k
Avg merge
1d 6h
Merged PRs (30d)
66

Description

### Bug report

I've recently found out that built-in colormaps doesn't exactly match the ones shown on the [colormap reference](https://matplotlib.org/stable/gallery/color/colormap_reference.html).

Here's an example for the viridis colormap :

Last color on the png is `#fde724`:
![Screenshot from 2021-06-17 13-12-13](https://user-images.githubusercontent.com/20096663/122386494-3c4d8e80-cf6e-11eb-9e65-26985bae7f0c.png)

Last color of the colormap is `#fde725`:
```python
In [35]: import matplotlib
...: from pylab import cm
...: colormap = cm.get_cmap("viridis")
...: matplotlib.colors.rgb2hex(colormap(colormap.N-1))
Out[35]: '#fde725'
```
I've tested only one other colormap (jet), and it had the same issue. Is there a reason for it ?

**Matplotlib version**

* Operating system: Ubuntu 20.04
* Matplotlib version 3.3.0 & 3.4.2
* Matplotlib backend TkAgg
* Python version: 3.8

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported discrepancy with Python 3.8, Matplotlib 3.3.0 or 3.4.2, and the `cm.get_cmap("viridis")` entry point. Compare the generated reference image with `matplotlib.colors.rgb2hex(colormap(colormap.N-1))`; done means identifying and documenting why the displayed and built-in colors differ, with a regression check if an appropriate test location is found.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.