Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
New color conversion machinery. #6382
Conversation
mdboom
added the
needs_review
label
May 8, 2016
|
Based on an initial scan of the code, I like it. It's much clearer and cleaner than the original. |
|
Can someone help with the test failures on python-2.7/numpy-1.6? I have never been able to locally get 100% matching images in the tests even on recent pythons and numpys so that'll be hard for me to investigate. |
|
The 2.7 test failures that have just now started appearing are all in the svg images, not png. Either something has changed in Travis, or there is a bad 2.7-specific interaction between the most recent commits and the svg backend. |
|
Perhaps it would be nice to add Python (most recent) / numpy 1.6 and Python 2.7 / numpy (most recent) to the test matrix to simplify the debugging here. Also, according to AppVeyor this passes with Python 2.7 / numpy 1.8... |
|
Got it, this was due to a change in the behavior of the builtin seaborn messes up with the color mapping (for good reasons IMO, and it was part of the public API anyways). I guess this means we should maintain it as public, and hide away the cache. Instead, the color mapping should detect changes to itself and reset the cache as needed. |
|
Regarding the docs build, it seems that the problem occurs as Travis is trying to download and install basemap from github. It has been failing more often than not today--but not always. |
|
For the docs issue see #6379 |
|
@anntzer, your new version of |
tacaswell
added this to the
2.1 (next point release)
milestone
May 8, 2016
tacaswell
closed this
May 8, 2016
tacaswell
reopened this
May 8, 2016
tacaswell
added needs_review and removed needs_review
labels
May 8, 2016
|
The latest commit should cover the performance issues. |
|
Another odd 2.7-only failure: in |
|
Apparently returning builtin floats instead of numpy floats solves the issue... |
mdboom
commented on the diff
May 9, 2016
| if color is not None: | ||
| raise ValueError( | ||
| 'Illegal format string "%s"; two color symbols' % fmt) | ||
| color = c | ||
| elif c == 'C' and i < len(chars) - 1: | ||
| color_cycle_number = int(chars[i + 1]) | ||
| - color = mcolors.colorConverter._get_nth_color(color_cycle_number) | ||
| + color = mcolors.to_rgba("C{}".format(color_cycle_number)) |
mdboom
Owner
|
|
Thanks for this much needed improvement. I have nothing to add to @efiring's comments. |
|
Moved 1-letter codes to their own mapping in |
|
I am It is a very old part of the public API so may have wide-spread use in user code and it is not onerous to continue supporting. |
|
Fair enough, but what about at least removing it from the docs (via sphinx' autodoc-skip-member), i.e. deprecate-in-docs? By the way, the current API entry is rather ugly: http://matplotlib.org/api/colors_api.html#matplotlib.colors.ColorConverter |
|
I am fine with removing it from the docs / re-writing those docs. On Mon, May 9, 2016 at 12:17 PM Antony Lee notifications@github.com wrote:
|
|
Now that we're there, what about replacing the "do-nothing" |
|
Also, I just noticed that there are collisions between css4 color names and xkcd color names (e.g., "yellow") -- this was why the previous commit broke the tests, as I overwrote the css4 colors with the xkcd colors instead of the other way round (now fixed). So I'm going to make another impopular (aka. backwards incompatible) proposal: rename all xkcd colors to "xkcd:", and remove the other aliases (it's not as if "xkcdpastel red" looked particularly nice either). |
|
We have not released the xckd colors yet so we can still break that. I think that should get its own issue separate from this (as that should be On Mon, May 9, 2016, 12:52 Antony Lee notifications@github.com wrote:
|
anntzer
referenced
this pull request
May 9, 2016
Merged
Use xkcd: prefix to avoid color name clashes. #6390
|
I am trying to work on the docs update but
which I have seen on Travis sometimes too. |
|
This should have been addressed by #6238 Have we not done the merge cascade yet? |
|
Rebasing on master did not help. |
|
Try downgrading to sphinx 1.3.x? |
tacaswell
commented on the diff
May 11, 2016
| - | ||
| -# Transform to hex color values. | ||
| -hex_ = [color[1] for color in colors_] | ||
| -# Get the rgb equivalent. | ||
| -rgb = [colors.hex2color(color) for color in hex_] | ||
| -# Get the hsv equivalent. | ||
| -hsv = [colors.rgb_to_hsv(color) for color in rgb] | ||
| - | ||
| -# Split the hsv values to sort. | ||
| -hue = [color[0] for color in hsv] | ||
| -sat = [color[1] for color in hsv] | ||
| -val = [color[2] for color in hsv] | ||
| - | ||
| -# Get the color names by themselves. | ||
| -names = [color[0] for color in colors_] | ||
| +colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS) |
anntzer
Contributor
|
tacaswell
commented on the diff
May 11, 2016
| @@ -1003,13 +999,13 @@ def on_combobox_lineprops_changed(self, item): | ||
| if marker is None: marker = 'None' | ||
| self.cbox_markers.set_active(self.markerd[marker]) | ||
| - r,g,b = colorConverter.to_rgb(line.get_color()) | ||
| - color = gtk.gdk.Color(*[int(val*65535) for val in (r,g,b)]) | ||
| + rgba = mcolors.to_rgba(line.get_color()) |
anntzer
Contributor
|
tacaswell
and 1 other
commented on an outdated diff
May 11, 2016
| -COLOR_NAMES = {'xkcd': XKCD_COLORS, | ||
| - 'css4': CSS4_COLORS} | ||
| +class _ColorMapping(dict): | ||
| + def __init__(self, mapping): | ||
| + super(_ColorMapping, self).__init__(mapping) | ||
| + self._cache = {} |
anntzer
Contributor
|
tacaswell
and 1 other
commented on an outdated diff
May 11, 2016
| + If `alpha` is not `None`, it forces the alpha value. | ||
| + """ | ||
| + # Special-case nth color syntax because it should not be cached. | ||
| + if _is_nth_color(c): | ||
| + from matplotlib import rcParams | ||
| + from matplotlib.rcsetup import cycler | ||
| + prop_cycler = rcParams['axes.prop_cycle'] | ||
| + if prop_cycler is None and 'axes.color_cycle' in rcParams: | ||
| + clist = rcParams['axes.color_cycle'] | ||
| + prop_cycler = cycler('color', clist) | ||
| + colors = prop_cycler._transpose()['color'] |
tacaswell
Owner
|
tacaswell
and 1 other
commented on an outdated diff
May 11, 2016
| + If `alpha` is not `None`, it forces the alpha value. | ||
| + """ | ||
| + # Special-case nth color syntax because it should not be cached. | ||
| + if _is_nth_color(c): | ||
| + from matplotlib import rcParams | ||
| + from matplotlib.rcsetup import cycler | ||
| + prop_cycler = rcParams['axes.prop_cycle'] | ||
| + if prop_cycler is None and 'axes.color_cycle' in rcParams: | ||
| + clist = rcParams['axes.color_cycle'] | ||
| + prop_cycler = cycler('color', clist) | ||
| + colors = prop_cycler._transpose()['color'] | ||
| + c = colors[int(c[1]) % len(colors)] | ||
| + try: | ||
| + rgba = _colors_full_map._cache[c, alpha] |
tacaswell
Owner
|
|
I like this I have wanted to get rid of that singleton for a while, but never got around to doing it. |
|
"this" being? |
|
the whole PR |
|
Sorry, I meant "that" (singleton). |
tacaswell
commented on the diff
May 11, 2016
| - if alpha is not None: | ||
| - if alpha > 1 or alpha < 0: | ||
| - raise ValueError("alpha must be in 0-1 range") | ||
| - result[:, 3] = alpha | ||
| - return result | ||
| - # This alpha operation above is new, and depends | ||
| - # on higher levels to refrain from setting alpha | ||
| - # to values other than None unless there is | ||
| - # intent to override any existing alpha values. | ||
| - | ||
| - # It must be some other sequence of color specs. | ||
| - result = np.zeros((nc, 4), dtype=np.float) | ||
| - for i, cc in enumerate(c): | ||
| - result[i] = self.to_rgba(cc, alpha) | ||
| - return result | ||
| + return to_rgba_array(arg, alpha) | ||
| colorConverter = ColorConverter() |
|
|
|
And I am suggesting making |
|
I feel like the main remaining question is whether we (mostly meaning you) want to draw an official policy w.r.t. changing the named color mapping. I agree that long names should not be modified, but I do like the remapping of one-letter codes by seaborn (because it makes making a plot with a consistent color style much easier). |
|
Rebased on master, restored |
|
Can you also add a Did you ever get the docs to build locally? |
|
This needs a Can you add a test where round-tripping a Other wise I am |
|
Actually I just realized one issue: should I did get the docs built after |
|
Yes, I don't see any benefit in tacking on "FF" willy-nilly. It's just noise. And it's not really part of the color. Alpha modifies the way colors are rendered when they overlap--it is not itself part of a color specification. |
|
OK, let's think of a better API (I do want to keep a way to convert to
which would drop alpha unless |
|
Maybe drop the |
|
Good suggestion, implemented. |
|
Sorry, I think I induced this merge by merging the xkcd rename branch |
|
...no? they're independent. (The Qt editor alpha depends on this one though.) |
|
This still needs a rebase |
anntzer
added some commits
May 6, 2016
|
Done. |
anntzer
added some commits
May 8, 2016
tacaswell
merged commit 22a7b95
into matplotlib:master
May 14, 2016
tacaswell
removed the
needs_review
label
May 14, 2016
|
@anntzer Thanks for this and thank you for putting up with our slow code review. |
anntzer
deleted the
anntzer:rgba-support branch
May 14, 2016
|
No worries, thanks. Also updated #6383 accordingly. |
tacaswell
added a commit
to tacaswell/matplotlib
that referenced
this pull request
May 16, 2016
|
|
tacaswell |
3281bcd
|
efiring
added a commit
that referenced
this pull request
May 16, 2016
|
|
efiring |
3b8a6ec
|
This was referenced May 19, 2016
|
Backport to v2.x is 3281bcd. |
QuLogic
modified the milestone: 2.0 (style change major release), 2.1 (next point release)
Jun 15, 2016
This was referenced Jun 28, 2016
tacaswell
added a commit
to QuLogic/matplotlib
that referenced
this pull request
Jan 16, 2017
|
|
tacaswell |
3d3130a
|
anntzer commentedMay 8, 2016
The main goal is to support
#rrggbbaahex color spec (#5461, #6196). The API is also considerably simplified: the conversion API is now reduced tois_color_like(c)to_rgba(c, alpha=None)to_rgba_array(c, alpha=None)to_hex(c, alpha=None)Full backwards compatibility is maintained (perhaps the compatibility layer should be deprecated in a later PR).