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

Skip to content

DOC: update colors from colormaps example #27708

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

Merged
merged 1 commit into from
Feb 4, 2024

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented Jan 26, 2024

PR summary

Follow up to #27678 based on comments there from @timhoffm.

PR checklist



from cycler import cycler

cmap = mpl.colormaps.get_cmap('Dark2')
colors = cmap(range(cmap.N)) # cmap.N is number of unique colors in the colormap
colors = mpl.colormaps['Dark2'].colors
Copy link
Member Author

@rcomer rcomer Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#27678 started out using the colors attribute but @jklymak said it could be confusing as LinearSegmentedColormap doesn't have it. Then @timhoffm suggested using it. I am hoping that using it after specifically stating that it's on ListedColormaps is a reasonable compromise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe turn that into a section heading to make it more obvious?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sectioning: The above should be something "Extracting values from a continuous colormap" (though technically most of the visually continous colormaps are still densely sampled ListedColormaps) and here "Extracting values from a discrete colormap".

I also suggest to not combine both the ListedColormap.colors explanation and the the rc_context into one plot. That's confusing. Either drop the rc_context, or make it a separate plot.

@rcomer
Copy link
Member Author

rcomer commented Jan 26, 2024

Renders like this

@rcomer rcomer added this to the v3.8-doc milestone Jan 26, 2024
Copy link
Member

@story645 story645 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comments since this hasn't been merged yet.


For more details about manipulating colormaps, see :ref:`colormap-manipulation`.
Once we have hold of a `.Colormap` instance, individual colors can be accessed by
passing one or more floats or integers. For more details about manipulating colormaps,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
passing one or more floats or integers. For more details about manipulating colormaps,
passing one or more floats or integers. For more details about manipulating colormaps,

Sorry for the late review, but passing to what?



from cycler import cycler

cmap = mpl.colormaps.get_cmap('Dark2')
colors = cmap(range(cmap.N)) # cmap.N is number of unique colors in the colormap
colors = mpl.colormaps['Dark2'].colors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe turn that into a section heading to make it more obvious?

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for leaving this hanging - too much to do.



from cycler import cycler

cmap = mpl.colormaps.get_cmap('Dark2')
colors = cmap(range(cmap.N)) # cmap.N is number of unique colors in the colormap
colors = mpl.colormaps['Dark2'].colors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sectioning: The above should be something "Extracting values from a continuous colormap" (though technically most of the visually continous colormaps are still densely sampled ListedColormaps) and here "Extracting values from a discrete colormap".

I also suggest to not combine both the ListedColormap.colors explanation and the the rc_context into one plot. That's confusing. Either drop the rc_context, or make it a separate plot.

@rcomer rcomer force-pushed the color-from-cmap-2 branch from d8e2594 to cca84fc Compare February 3, 2024 17:09
@rcomer
Copy link
Member Author

rcomer commented Feb 3, 2024

Thanks @story645, @timhoffm. How's this?

@timhoffm
Copy link
Member

timhoffm commented Feb 3, 2024

Thanks, this looks good! I would also say that @story645's comment is addressed, but let's give her the final word.

@story645 story645 merged commit 525349b into matplotlib:main Feb 4, 2024
@story645
Copy link
Member

story645 commented Feb 4, 2024

Awesome, thanks @rcomer !

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Feb 4, 2024
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Feb 4, 2024
story645 added a commit that referenced this pull request Feb 4, 2024
…708-on-v3.8.2-doc

Backport PR #27708 on branch v3.8.2-doc (DOC: update colors from colormaps example)
story645 added a commit that referenced this pull request Feb 4, 2024
…708-on-v3.8.x

Backport PR #27708 on branch v3.8.x (DOC: update colors from colormaps example)
@rcomer rcomer deleted the color-from-cmap-2 branch February 4, 2024 14:23
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.

4 participants