8000 Merge pull request #1505 from tacaswell/issue1504 · matplotlib/matplotlib@09b9c04 · GitHub
[go: up one dir, main page]

Skip to content

Commit 09b9c04

Browse files
committed
Merge pull request #1505 from tacaswell/issue1504
NF - Transparency for markers.
2 parents f2ff060 + dcdbc5a commit 09b9c04

File tree

6 files changed

+325
-6
lines changed

6 files changed

+325
-6
lines changed

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
an active colorable artist, such as an image, and just sets
2222
up the colormap to use from that point forward. - PI
2323

24+
2012-11-16 Added the funcction _get_rbga_face, which is identical to
25+
_get_rbg_face except it return a (r,g,b,a) tuble, to line2D.
26+
Modified Line2D.draw to use _get_rbga_face to get the markerface
27+
color so that any alpha set by markerfacecolor will respected.
28+
- Thomas Caswell
29+
2430
2012-11-13 Add a symmetric log normalization class to colors.py.
2531
Also added some tests for the normalization class.
2632
Till Stensitzki

lib/matplotlib/lines.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,12 @@ def draw(self, renderer):
531531
if self._marker:
532532
gc = renderer.new_gc()
533533
self._set_gc_clip(gc)
534-
rgbFace = self._get_rgb_face()
535-
rgbFaceAlt = self._get_rgb_face(alt=True)
534+
rgbaFace = self._get_rgba_face()
535+
rgbaFaceAlt = self._get_rgba_face(alt=True)
536536
edgecolor = self.get_markeredgecolor()
537537
if is_string_like(edgecolor) and edgecolor.lower() == 'none':
538538
gc.set_linewidth(0)
539-
gc.set_foreground(rgbFace)
539+
gc.set_foreground(rgbaFace)
540540
else:
541541
gc.set_foreground(edgecolor)
542542
gc.set_linewidth(self._markeredgewidth)
@@ -574,16 +574,20 @@ def draw(self, renderer):
574574
marker_trans = marker_trans.scale(w)
575575
else:
576576
gc.set_linewidth(0)
577+
if rgbaFace is not None:
578+
gc.set_alpha(rgbaFace[3])
577579
renderer.draw_markers(
578580
gc, marker_path, marker_trans, subsampled, affine.frozen(),
579-
rgbFace)
581+
rgbaFace)
580582
alt_marker_path = marker.get_alt_path()
581583
if alt_marker_path:
584+
if rgbaFaceAlt is not None:
585+
gc.set_alpha(rgbaFaceAlt[3])
582586
alt_marker_trans = marker.get_alt_transform()
583587
alt_marker_trans = alt_marker_trans.scale(w)
584588
renderer.draw_markers(
585589
gc, alt_marker_path, alt_marker_trans, subsampled,
586-
affine.frozen(), rgbFaceAlt)
590+
affine.frozen(), rgbaFaceAlt)
587591

588592
gc.restore()
589593

@@ -955,12 +959,20 @@ def update_from(self, other):
955959

956960
def _get_rgb_face(self, alt=False):
957961
facecolor = self._get_markerfacecolor(alt=alt)
958-
if is_string_like(facecolor) and facecolor.lower()=='none':
962+
if is_string_like(facecolor) and facecolor.lower() == 'none':
959963
rgbFace = None
960964
else:
961965
rgbFace = colorConverter.to_rgb(facecolor)
962966
return rgbFace
963967

968+
def _get_rgba_face(self, alt=False):
969+
facecolor = self._get_markerfacecolor(alt=alt)
970+
if is_string_like(facecolor) and facecolor.lower() == 'none':
971+
rgbaFace = None
972+
else:
973+
rgbaFace = colorConverter.to_rgba(facecolor)
974+
return rgbaFace
975+
964976
# some aliases....
965977
def set_aa(self, val):
966978
'alias for set_antialiased'
Binary file not shown.
Loading
Lines changed: 289 additions & 0 deletions
Loading

lib/matplotlib/tests/test_axes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,7 @@ def test_transparent_markers():
962962
ax = fig.add_subplot(111)
963963
ax.plot(data, 'D', mfc='none', markersize=100)
964964

965+
965966
@cleanup
966967
def test_mollweide_forward_inverse_closure():
967968
# test that the round-trip Mollweide forward->inverse transformation is an
@@ -1005,6 +1006,17 @@ def test_mollweide_inverse_forward_closure():
10051006
# compare
10061007
np.testing.assert_array_almost_equal(xy, xy2, 3)
10071008

1009+
1010+
@image_comparison(baseline_images=['translucent_markers'], remove_text=True)
1011+
def test_translucent_markers():
1012+
np.random.seed(0)
1013+
data = np.random.random(50)
1014+
1015+
fig = plt.figure()
1016+
ax = fig.add_subplot(111)
1017+
ax.plot(data, 'D', mfc=[1, 0, 0, .5], markersize=100)
1018+
1019+
10081020
if __name__=='__main__':
10091021
import nose
10101022
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

0 commit comments

Comments
 (0)
0