-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Enh color shadding #8895
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
Enh color shadding #8895
Conversation
…ken a given color by a given percentage
…ken a given color by a given percentage (altered CC to ColorConverter)
…ken a given color by a given percentage, added modifications noted in PR matplotlib#2745 which included fixing PEP8 errors and adding a test.
…ken a given color by a given percentage, added modifications noted in PR matplotlib#2745 which included fixing PEP8 errors and adding a test.
@@ -0,0 +1,9 @@ | |||
Easy color shading | |||
`````````````````` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be ----
|
||
h, l, s = rgb_to_hls(*rgb) | ||
|
||
l *= 1 + float(percent)/100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just use 0.5
instead of 50
here, and remove divide by 100s? Percentages are dumb units, and we already avoid them for [r,g,b]
colors, so let's not introduce them here either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems reasonable.
@@ -1947,3 +1950,38 @@ def from_levels_and_colors(levels, colors, extend='neither'): | |||
|
|||
norm = BoundaryNorm(levels, ncolors=n_data_colors) | |||
return cmap, norm | |||
|
|||
|
|||
def shade_color(color, percent): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In almost all of the other color code we handle fractions as floats in range [0, 1]
, should do the same here.
Any acceptable Matplotlib color value, such as 'red', | ||
'slategrey', '#FFEE11', (1,0,0) | ||
|
||
percent : the amount by which to brighten or darken the color. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specify units and range
tuple representing converted rgb values | ||
|
||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should do some validation on the scaling
|
||
h, l, s = rgb_to_hls(*rgb) | ||
|
||
l *= 1 + float(percent)/100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems reasonable.
@@ -64,9 +64,12 @@ | |||
from collections import Sized | |||
import re | |||
import warnings | |||
from colorsys import rgb_to_hls, hls_to_rgb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing these publicly is a bad idea, because it makes matplotlib.colors.rgb_to_hsv
and matplotlib.colors.rgb_to_hls
look similar, when they have completely different argument conventions
This color utility function allows the user to easily darken or | ||
lighten a color for plotting purposes. This function first | ||
converts the given color to RGB using ColorConverter and then to | ||
HSL. The saturation is modified according to the given percentage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Genuine remark about what may be a typo: it is the lightness ("l" in "hls") that is modified by this function, not the saturation ("s" in "hls"), isn't it?
Closing in lieu of #9985. Feel free to comment there... |
Rebase of #2745
If anyone is interested in working on this please take it over!
This still needs
PR Summary
Provides the ability to 'lighten' or 'darken' a color.
PR Checklist