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

Skip to content

Commit 2cdcc03

Browse files
committed
Fix validation of Line2D color.
We don't actually support color="auto" (we only support mfc="auto" and mec="auto", which mean "use the main color") -- with the sole exception of axisartist Ticks, which is a subclass that has special handling for "auto". This can easily be tested using `plt.plot([1, 2], c="auto")` which crashes.
1 parent 3efd447 commit 2cdcc03

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

lib/matplotlib/lines.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,8 +1027,7 @@ def set_color(self, color):
10271027
----------
10281028
color : color
10291029
"""
1030-
if not cbook._str_equal(color, 'auto'):
1031-
mcolors._check_color_like(color=color)
1030+
mcolors._check_color_like(color=color)
10321031
self._color = color
10331032
self.stale = True
10341033

lib/mpl_toolkits/axisartist/axis_artist.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@
7575

7676
import numpy as np
7777

78-
from matplotlib import _api, rcParams
78+
from matplotlib import _api, cbook, rcParams
7979
import matplotlib.artist as martist
80+
import matplotlib.colors as mcolors
8081
import matplotlib.text as mtext
81-
8282
from matplotlib.collections import LineCollection
8383
from matplotlib.lines import Line2D
8484
from matplotlib.patches import PathPatch
@@ -134,6 +134,14 @@ def get_ref_artist(self):
134134
# docstring inherited
135135
return self._axis.majorTicks[0].tick1line
136136

137+
def set_color(self, color):
138+
# docstring inherited
139+
# Unlike the base Line2D.set_color, this also supports "auto".
140+
if not cbook._str_equal(color, "auto"):
141+
mcolors._check_color_like(color=color)
142+
self._color = color
143+
self.stale = True
144+
137145
def get_color(self):
138146
return self.get_attribute_from_ref_artist("color")
139147

0 commit comments

Comments
 (0)