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 | |||
| `````````````````` | |||
|
|
||
| h, l, s = rgb_to_hls(*rgb) | ||
|
|
||
| l *= 1 + float(percent)/100 |
There was a problem hiding this comment.
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.
That seems reasonable.
| return cmap, norm | ||
|
|
||
|
|
||
| def shade_color(color, percent): |
There was a problem hiding this comment.
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.
specify units and range
| tuple representing converted rgb values | ||
|
|
||
| """ | ||
|
|
There was a problem hiding this comment.
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.
That seems reasonable.
| from collections import Sized | ||
| import re | ||
| import warnings | ||
| from colorsys import rgb_to_hls, hls_to_rgb |
There was a problem hiding this comment.
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.
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