Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e807990

Browse files
committed
Merge pull request #2761 from tacaswell/fix_line_color_handling
Fix line color handling
2 parents 3d297ff + cc1756a commit e807990

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lib/matplotlib/lines.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def draw(self, renderer):
527527
self._set_gc_clip(gc)
528528

529529
ln_color_rgba = self._get_rgba_ln_color()
530-
gc.set_foreground(ln_color_rgba)
530+
gc.set_foreground(ln_color_rgba, isRGBA=True)
531531
gc.set_alpha(ln_color_rgba[3])
532532

533533
gc.set_antialiased(self._antialiased)
@@ -569,7 +569,7 @@ def draw(self, renderer):
569569
edgecolor = self.get_markeredgecolor()
570570
if is_string_like(edgecolor) and edgecolor.lower() == 'none':
571571
gc.set_linewidth(0)
572-
gc.set_foreground(rgbaFace)
572+
gc.set_foreground(rgbaFace, isRGBA=True)
573573
else:
574574
gc.set_foreground(edgecolor)
575575
gc.set_linewidth(self._markeredgewidth)
@@ -1031,12 +1031,7 @@ def _get_rgba_face(self, alt=False):
10311031
return rgbaFace
10321032

10331033
def _get_rgba_ln_color(self, alt=False):
1034-
ln_color = self._color
1035-
if is_string_like(ln_color) and ln_color.lower() == 'none':
1036-
rgba_ln = None
1037-
else:
1038-
rgba_ln = colorConverter.to_rgba(ln_color, self._alpha)
1039-
return rgba_ln
1034+
return colorConverter.to_rgba(self._color, self._alpha)
10401035

10411036
# some aliases....
10421037
def set_aa(self, val):

lib/matplotlib/tests/test_lines.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
def test_invisible_Line_rendering():
1515
"""
1616
Github issue #1256 identified a bug in Line.draw method
17-
17+
1818
Despite visibility attribute set to False, the draw method was not
1919
returning early enough and some pre-rendering code was executed
2020
though not necessary.
@@ -67,6 +67,19 @@ def test_set_line_coll_dash():
6767
assert True
6868

6969

70+
@cleanup
71+
def test_line_colors():
72+
fig = plt.figure()
73+
ax = fig.add_subplot(1, 1, 1)
74+
ax.plot(range(10), color='none')
75+
ax.plot(range(10), color='r')
76+
ax.plot(range(10), color='.3')
77+
ax.plot(range(10), color=(1, 0, 0, 1))
78+
ax.plot(range(10), color=(1, 0, 0))
79+
fig.canvas.draw()
80+
assert True
81+
82+
7083
@image_comparison(baseline_images=['line_collection_dashes'], remove_text=True)
7184
def test_set_line_coll_dash_image():
7285
fig = plt.figure()

0 commit comments

Comments
 (0)