8000 DOC: Update color tutorial to explain alpha · matplotlib/matplotlib@b0b7286 · GitHub
[go: up one dir, main page]

Skip to content

Commit b0b7286

Browse files
committed
DOC: Update color tutorial to explain alpha
1 parent baa5f8e commit b0b7286

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,6 @@ def is_saving(self):
18041804
"""
18051805
return self._is_saving
18061806

1807-
@cbook.deprecated("2.2")
18081807
def onRemove(self, ev):
18091808
"""
18101809
Mouse event processor which removes the top artist
@@ -2697,7 +2696,6 @@ def key_press(self, event):
26972696
if rcParams['toolbar'] != 'toolmanager':
26982697
key_press_handler(event, self.canvas, self.canvas.toolbar)
26992698

2700-
@cbook.deprecated("2.2")
27012699
def show_popup(self, msg):
27022700
"""Display message in a popup -- GUI only."""
27032701

@@ -3220,13 +3218,6 @@ class ToolContainerBase(object):
32203218
The tools with which this `ToolContainer` wants to communicate.
32213219
"""
32223220

3223-
_icon_extension = '.png'
3224-
"""
3225-
Toolcontainer button icon image format extension
3226-
3227-
**String**: Image extension
3228-
"""
3229-
32303221
def __init__(self, toolmanager):
32313222
self.toolmanager = toolmanager
32323223
self.toolmanager.toolmanager_connect('tool_removed_event',
@@ -3271,19 +3262,14 @@ def _remove_tool_cbk(self, event):
32713262

32723263
def _get_image_filename(self, image):
32733264
"""Find the image based on its name."""
3274-
if not image:
3275-
return None
3276-
3265+
# TODO: better search for images, they are not always in the
3266+
# datapath
32773267
basedir = os.path.join(rcParams['datapath'], 'images')
3278-
possible_images = (
3279-
image,
3280-
image + self._icon_extension,
3281-
os.path.join(basedir, image),
3282-
os.path.join(basedir, image) + self._icon_extension)
3283-
3284-
for fname in possible_images:
3285-
if os.path.isfile(fname):
3286-
return fname
3268+
if image is not None:
3269+
fname = os.path.join(basedir, image)
3270+
else:
3271+
fname = None
3272+
return fname
32873273

32883274
def trigger_tool(self, name):
32893275
"""

tutorials/colors/colors.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Matplotlib recognizes the following formats to specify a color:
77
88
* an RGB or RGBA tuple of float values in ``[0, 1]`` (e.g., ``(0.1, 0.2, 0.5)``
9-
or ``(0.1, 0.2, 0.5, 0.3)``);
9+
or ``(0.1, 0.2, 0.5, 0.3)``). RGBA is short for Red, Green, Blue, Alpha;
1010
* a hex RGB or RGBA string (e.g., ``'#0F0F0F'`` or ``'#0F0F0F0F'``);
1111
* a string representation of a float value in ``[0, 1]`` inclusive for gray
1212
level (e.g., ``'0.5'``);
@@ -23,6 +23,19 @@
2323
the indexing occurs at artist creation time and defaults to black if the
2424
cycle does not include color.
2525
26+
"Red", "Green" and "Blue", are the intensities of those colors, the combination
27+
of which span the colorspace.
28+
29+
How "Alpha" behaves depends on the ``zorder`` of the Artist. Higher
30+
`zorder` Artists are drawn on top of lower Artists, and "Alpha" determines
31+
whether the lower artist is covered by the higher.
32+
If the old RGB of a pixel is ``RGBold`` and the RGB of the
33+
pixel of the Artist being added is ``RGBnew`` with Alpha ``alpha``,
34+
then the RGB of the pixel is updated to:
35+
``RGB = RGBOld * (1 - Alpha) + RGBnew * Alpha``. Alpha
36+
of 1 means the old color is completely covered by the new Artist, Alpha of 0
37+
means that pixel of the Artist is transparent.
38+
2639
All string specifications of color, other than "CN", are case-insensitive.
2740
2841
"CN" color selection

0 commit comments

Comments
 (0)
0