Skip to content
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

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

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG
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
22 changes: 17 additions & 5 deletions lib/matplotlib/lines.py
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 @@ -961,6 +965,14 @@ def _get_rgb_face(self, alt=False):
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':
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 be spaces around ==

rgbaFace = None
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.
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_axes.py
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,19 @@ 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)
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 be spaces after ,



Copy link
Member

Choose a reason for hiding this comment

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

Same here :)

Copy link
Member

Choose a reason for hiding this comment

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

(2 blank lines except of 3)


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