-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
New color conversion machinery. #6382
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
Changes from all commits
f6f908e
75b0d13
72f34be
09a0f4c
2fe2c26
5a4432c
bc6ad2a
d9db062
cb3d7c9
d492ba4
7c2ec4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Improved color conversion API and RGBA support | ||
---------------------------------------------- | ||
|
||
The :module:`~matplotlib.colors` gained a new color conversion API with | ||
full support for the alpha channel. The main public functions are | ||
:func:`~matplotlib.colors.is_color_like`, :func:`matplotlib.colors.to_rgba`, | ||
:func:`matplotlib.colors.to_rgba_array` and :func:`~matplotlib.colors.to_hex`. | ||
RGBA quadruplets are encoded in hex format as `#rrggbbaa`. | ||
|
||
A side benefit is that the Qt options editor now allows setting the alpha | ||
channel of the artists as well. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,7 @@ def _process_plot_format(fmt): | |
|
||
# Is fmt just a colorspec? | ||
try: | ||
color = mcolors.colorConverter.to_rgb(fmt) | ||
color = mcolors.to_rgba(fmt) | ||
|
||
# We need to differentiate grayscale '1.0' from tri_down marker '1' | ||
try: | ||
|
@@ -112,14 +112,14 @@ def _process_plot_format(fmt): | |
raise ValueError( | ||
'Illegal format string "%s"; two marker symbols' % fmt) | ||
marker = c | ||
elif c in mcolors.colorConverter.colors: | ||
elif c in mcolors.get_named_colors_mapping(): | ||
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still like the idea of using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous version may look format independent, but if you check the parsing code just around it it's clearly also dependent on the exact format of CN colors. Plus, it uses a private API. (And I wouldn't worry too much about the performance implications of doing an extra regexp match.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a wash either way. The On the other hand, it is our policy that we can use mpl private API anywhere in the mpl code base (that is the point of the private APIs). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to think that private APIs are module-level (or class-level) private (rather than project-level), but don't feel strongly about this so either way works for me. |
||
i += 1 | ||
else: | ||
raise ValueError( | ||
|
@@ -3687,7 +3687,7 @@ def set_cursor_props(self, *args): | |
lw, c = args | ||
else: | ||
raise ValueError('args must be a (linewidth, color) tuple') | ||
c = mcolors.colorConverter.to_rgba(c) | ||
c = mcolors.to_rgba(c) | ||
self._cursorProps = lw, c | ||
|
||
def get_children(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,15 +35,11 @@ def fn_name(): return sys._getframe(1).f_code.co_name | |
|
||
from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK | ||
from matplotlib.cbook import is_string_like, is_writable_file_like | ||
from matplotlib.colors import colorConverter | ||
from matplotlib.figure import Figure | ||
from matplotlib.widgets import SubplotTool | ||
|
||
from matplotlib import lines | ||
from matplotlib import markers | ||
from matplotlib import cbook | ||
from matplotlib import verbose | ||
from matplotlib import rcParams | ||
from matplotlib import ( | ||
cbook, colors as mcolors, lines, markers, rcParams, verbose) | ||
|
||
backend_version = "%d.%d.%d" % gtk.pygtk_version | ||
|
||
|
@@ -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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a reasonable place to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does GTK have the concept of an RGBA color? (Not according to http://www.pygtk.org/pygtk2reference/class-gdkcolor.html, but I don't known much about GTK...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fariza is the GTK expert. There are some applications which do not know / use / care about alpha, forcing all of them to explicitly drop the last value is falling a bit too far to the 'purity' side of API design. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I have restored There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a section of the code that I was waiting for MEP27 to get rid of it. I plan to introduce the same functionality as generic tool for all the backends. This class The class was copy/paste to Gtk3 but last time I checked it wasn't working. My advice would be, if the example runs, then it is fine. (I don't have a working gtk2 environment anymore to test) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example runs with py2/gtk2. However, it is the typical example of why I want to get rid of |
||
color = gtk.gdk.Color(*[int(val*65535) for val in rgba[:3]]) | ||
button = self.wtree.get_widget('colorbutton_linestyle') | ||
button.set_color(color) | ||
|
||
r,g,b = colorConverter.to_rgb(line.get_markerfacecolor()) | ||
color = gtk.gdk.Color(*[int(val*65535) for val in (r,g,b)]) | ||
rgba = mcolors.to_rgba(line.get_markerfacecolor()) | ||
color = gtk.gdk.Color(*[int(val*65535) for val in rgba[:3]]) | ||
button = self.wtree.get_widget('colorbutton_markerface') | ||
button.set_color(color) | ||
self._updateson = True | ||
|
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.
Add xkcd here or does that just blow the example up too much?
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.
Try making a figure with 3244 lines and text elements and get back to me :-)
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.
fair point.