Skip to content

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

Closed
wants to merge 4 commits into from
Closed

Conversation

tacaswell
Copy link
Member

Rebase of #2745

If anyone is interested in working on this please take it over!

This still needs

  • support for alpha (should just pass through value from color)
  • convert the example to sphinx-gallery

PR Summary

Provides the ability to 'lighten' or 'darken' a color.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/whats_new.rst if major new feature

dvreed77 added 4 commits July 16, 2017 09:59
…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.
@tacaswell tacaswell added this to the 2.2 (next next feature release) milestone Jul 16, 2017
@tacaswell tacaswell mentioned this pull request Jul 16, 2017
@@ -0,0 +1,9 @@
Easy color shading
``````````````````
Copy link
Contributor

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
Copy link
Contributor

@eric-wieser eric-wieser Jul 16, 2017

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.

Copy link
Member Author

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):
Copy link
Member Author

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.
Copy link
Member Author

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

"""

Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Contributor

@eric-wieser eric-wieser Jul 16, 2017

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
Copy link
Contributor

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?

@tacaswell tacaswell added the Good first issue Open a pull request against these issues if there are no active ones! label Oct 16, 2017
@jklymak jklymak mentioned this pull request Dec 12, 2017
5 tasks
@jklymak
Copy link
Member

jklymak commented Dec 12, 2017

Closing in lieu of #9985. Feel free to comment there...

@jklymak jklymak closed this Dec 12, 2017
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0, unassigned Feb 13, 2018
@tacaswell tacaswell deleted the enh_color_shadding branch November 4, 2019 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Open a pull request against these issues if there are no active ones!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants