8000 Issue 1504: changed how `draw` handles alpha in `markerfacecolor` by tacaswell · Pull Request #1505 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Issue 1504: changed how draw handles alpha in markerfacecolor #1505

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

Merged
merged 5 commits into from
Jan 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
an active colorable artist, such as an image, and just sets
up the colormap to use from that point forward. - PI

2012-11-16 Added the funcction _get_rbga_face, which is identical to
_get_rbg_face except it return a (r,g,b,a) tuble, to line2D.
Modified Line2D.draw to use _get_rbga_face to get the markerface
color so that any alpha set by markerfacecolor will respected.
- Thomas Caswell

2012-11-13 Add a symmetric log normalization class to colors.py.
Also added some tests for the normalization class.
Till Stensitzki
Expand Down
24 changes: 18 additions & 6 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,12 @@ def draw(self, renderer):
if self._marker:
gc = renderer.new_gc()
self._set_gc_clip(gc)
rgbFace = self._get_rgb_face()
rgbFaceAlt = self._get_rgb_face(alt=True)
rgbaFace = self._get_rgba_face()
rgbaFaceAlt = self._get_rgba_face(alt=True)
edgecolor = self.get_markeredgecolor()
if is_string_like(edgecolor) and edgecolor.lower() == 'none':
gc.set_linewidth(0)
gc.set_foreground(rgbFace)
gc.set_foreground(rgbaFace)
else:
gc.set_foreground(edgecolor)
gc.set_linewidth(self._markeredgewidth)
Expand Down Expand Up @@ -574,16 +574,20 @@ def draw(self, renderer):
marker_trans = marker_trans.scale(w)
else:
gc.set_linewidth(0)
if rgbaFace is not None:
gc.set_alpha(rgbaFace[3])
renderer.draw_markers(
gc, marker_path, marker_trans, subsampled, affine.frozen(),
rgbFace)
rgbaFace)
alt_marker_path = marker.get_alt_path()
if alt_marker_path:
if rgbaFaceAlt is not None:
gc.set_alpha(rgbaFaceAlt[3])
alt_marker_trans = marker.get_alt_transform()
alt_marker_trans = alt_marker_trans.scale(w)
renderer.draw_markers(
gc, alt_marker_path, alt_marker_trans, subsampled,
affine.frozen(), rgbFaceAlt)
affine.frozen(), rgbaFaceAlt)

gc.restore()

Expand Down Expand Up @@ -955,12 +959,20 @@ def update_from(self, other):

def _get_rgb_face(self, alt=False):
facecolor = self._get_markerfacecolor(alt=alt)
if is_string_like(facecolor) and facecolor.lower()=='none':
if is_string_like(facecolor) and facecolor.lower() == 'none':
rgbFace = None
else:
rgbFace = colorConverter.to_rgb(facecolor)
return rgbFace

def _get_rgba_face(self, alt=False):
facecolor = self._get_markerfacecolor(alt=alt)
if is_string_like(facecolor) and facecolor.lower() == 'none':
rgbaFace = None
< 10000 /td> else:
rgbaFace = colorConverter.to_rgba(facecolor)
return rgbaFace

# some aliases....
def set_aa(self, val):
'alias for set_antialiased'
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
289 changes: 289 additions & 0 deletions lib/matplotlib/tests/baseline_images/test_axes/translucent_markers.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ def test_transparent_markers():
ax = fig.add_subplot(111)
ax.plot(data, 'D', mfc='none', markersize=100)


@cleanup
def test_mollweide_forward_inverse_closure():
# test that the round-trip Mollweide forward->inverse transformation is an
Expand Down Expand Up @@ -1005,6 +1006,17 @@ def test_mollweide_inverse_forward_closure():
# compare
np.testing.assert_array_almost_equal(xy, xy2, 3)


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8 nitpick: there should 2 blank lines and not 3 here

@image_comparison(baseline_images=['translucent_markers'], remove_text=True)
def test_translucent_markers():
np.random.seed(0)
data = np.random.random(50)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(data, 'D', mfc=[1, 0, 0, .5], markersize=100)


if __name__=='__main__':
import nose
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
Expand Down
0