8000 ConfusionMatrixDisplay miscolors text if colormap has more than 256 colors · Issue #19777 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content
< 8000 template class="js-flash-template">

ConfusionMatrixDisplay miscolors text if colormap has more than 256 colors #19777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
michael-s-crouch opened this issue Mar 29, 2021 · 0 comments · Fixed by #19784
Closed

ConfusionMatrixDisplay miscolors text if colormap has more than 256 colors #19777

michael-s-crouch opened this issue Mar 29, 2021 · 0 comments · Fixed by #19784

Comments

@michael-s-crouch
Copy link

Describe the bug

When ConfusionMatrixDisplay is deciding on text colors, it uses colormap entry 256 as the text color for labeling cells below the mean value. This is line 125 of metrics/_plot/confusion_matrix.py:
cmap_min, cmap_max = self.im_.cmap(0), self.im_.cmap(256)

This causes incorrect coloring and hard-to-read graphs if using a ListedColormap with more than 256 entries. (Which was necessary for my application because I needed to renormalize the colormap)

Steps/Code to Reproduce

import numpy as np
import matplotlib
import matplotlib.cm
from sklearn.metrics import ConfusionMatrixDisplay

def getMapWith(colors):
    ans = matplotlib.cm.get_cmap('gray')(np.linspace(0, 1, colors)) ** 0.5 
    return matplotlib.colors.ListedColormap(ans)
x = np.random.rand(3, 3)
disp = ConfusionMatrixDisplay(x)

disp.plot(cmap=getMapWith(256)) # Works great
disp.plot(cmap=getMapWith(1024)) # Can't read

Versions

System:
    python: 3.8.5 (default, Jul 28 2020, 12:59:40)  [GCC 9.3.0]
executable: /home/mcrouch/test2/env/bin/python
   machine: Linux-5.4.0-47-generic-x86_64-with-glibc2.29

Python dependencies:
          pip: 21.0.1
   setuptools: 54.1.2
      sklearn: 0.24.1
        numpy: 1.19.5
        scipy: 1.6.1
       Cython: None
       pandas: 1.2.3
   matplotlib: 3.3.4
       joblib: 1.0.1
threadpoolctl: 2.1.0

Built with OpenMP: True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0