Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[WIP] Categorical Color Mapping #6934

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
wants to merge 5 commits into from
Closed

Conversation

story645
Copy link
Member

@story645 story645 commented Aug 10, 2016

Start of a PR to simplify creating colormaps for categorical data such that (key, value) pairs can be used - and then reused in other functions. Currently using ListedColormap alone requires one to mentally sort the data and then list colors accordingly, as does using ListedColormap+BoundaryNorm, and the latter also requires an upper boundary that is unintuitive for data that isn't interval. This aims to somewhat address #6214 & #6802

This is just a teeny wrapper over colors.ListedColormap and colors.BoundaryNorm (which is probably the wrong thing to do and I should write a CategoryNorm to do 1 int to 1 color mapping) in the style of colors.from_levels_and_colors that allows users to do this:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.category as cat

data = np.array([[205,101,302], [205,302,101], [302,205,101]])

codings = {205:"red", 101:"blue", 302:"green"}
cmap, norm = cat.colors_from_categories(codings)

sm = plt.imshow(a, cmap=cmap, norm=norm)

index

This is all tentative, but next steps are:

  • write CategoryNorm
  • extend categorical support to imshow
  • extend categorical to scatter markers
  • get this hooked into legend since that makes more sense than colorbar anyway
  • sort out the colorbar

Also, this PR is dependent on #6920 since it uses py.test and branches off of #6889 because it may need those features.

More notes:

Need to change when imshow does it's casting, currently too early
Makes use of StrCategoricalConverter
Conversion gets stashed in Norm, which seems to be the place to do unit stuff on scaler mappables since it's the level at which value mapping happens anyway...

@tacaswell tacaswell modified the milestone: 2.1 (next point release) Oct 11, 2016
@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Aug 29, 2017
@story645 story645 modified the milestones: v2.2, v3.0 Feb 6, 2018
@story645
Copy link
Member Author

story645 commented May 9, 2018

closing in favor of a norm based approach + specialized legend for discrete norms discussed in #7383

@story645 story645 closed this May 9, 2018
@story645 story645 deleted the color branch May 9, 2018 20:21
@QuLogic QuLogic removed this from the v3.0 milestone May 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants