Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c62b3c4

Browse filesBrowse files
authored
Fix marker validator with cycler (allow mix of classes) #27613
Add test Add stubs Private functions & updated test Update test Co-authored-by: Kyle Sunden <git@ksunden.space> Add test Private functions & updated test
1 parent 83aa3e4 commit c62b3c4
Copy full SHA for c62b3c4

File tree

Expand file treeCollapse file tree

3 files changed

+26
-5
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+26
-5
lines changed

‎lib/matplotlib/rcsetup.py

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.py
+19-5Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ def validator(s):
209209
validate_float, doc='return a list of floats')
210210

211211

212+
def _validate_marker(s):
213+
try:
214+
return validate_int(s)
215+
except ValueError as e:
216+
try:
217+
return validate_string(s)
218+
except ValueError as e:
219+
raise ValueError('Supported markers are [string, int]') from e
220+
221+
222+
_validate_markerlist = _listify_validator(
223+
_validate_marker, doc='return a list of markers')
224+
225+
212226
def _validate_pathlike(s):
213227
if isinstance(s, (str, os.PathLike)):
214228
# Store value as str because savefig.directory needs to distinguish
@@ -645,7 +659,7 @@ def _validate_minor_tick_ndivs(n):
645659
'markeredgecolor': validate_colorlist,
646660
'markevery': validate_markeverylist,
647661
'alpha': validate_floatlist,
648-
'marker': validate_stringlist,
662+
'marker': _validate_markerlist,
649663
'hatch': validate_hatchlist,
650664
'dashes': validate_dashlist,
651665
}
@@ -908,7 +922,7 @@ def _convert_validator_spec(key, conv):
908922
"lines.linewidth": validate_float, # line width in points
909923
"lines.linestyle": _validate_linestyle, # solid line
910924
"lines.color": validate_color, # first color in color cycle
911-
"lines.marker": validate_string, # marker name
925+
"lines.marker": _validate_marker, # marker name
912926
"lines.markerfacecolor": validate_color_or_auto, # default color
913927
"lines.markeredgecolor": validate_color_or_auto, # default color
914928
"lines.markeredgewidth": validate_float,
@@ -957,7 +971,7 @@ def _convert_validator_spec(key, conv):
957971
"boxplot.meanline": validate_bool,
958972

959973
"boxplot.flierprops.color": validate_color,
960-
"boxplot.flierprops.marker": validate_string,
974+
"boxplot.flierprops.marker": _validate_marker,
961975
"boxplot.flierprops.markerfacecolor": validate_color_or_auto,
962976
"boxplot.flierprops.markeredgecolor": validate_color,
963977
"boxplot.flierprops.markeredgewidth": validate_float,
@@ -982,7 +996,7 @@ def _convert_validator_spec(key, conv):
982996
"boxplot.medianprops.linestyle": _validate_linestyle,
983997

984998
"boxplot.meanprops.color": validate_color,
985-
"boxplot.meanprops.marker": validate_string,
999+
"boxplot.meanprops.marker": _validate_marker,
9861000
"boxplot.meanprops.markerfacecolor": validate_color,
9871001
"boxplot.meanprops.markeredgecolor": validate_color,
9881002
"boxplot.meanprops.markersize": validate_float,
@@ -1107,7 +1121,7 @@ def _convert_validator_spec(key, conv):
11071121
"axes3d.zaxis.panecolor": validate_color, # 3d background pane
11081122

11091123
# scatter props
1110-
"scatter.marker": validate_string,
1124+
"scatter.marker": _validate_marker,
11111125
"scatter.edgecolors": validate_string,
11121126

11131127
"date.epoch": _validate_date,

‎lib/matplotlib/rcsetup.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.pyi
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def validate_int_or_None(s: Any) -> int | None: ...
3939
def validate_float(s: Any) -> float: ...
4040
def validate_float_or_None(s: Any) -> float | None: ...
4141
def validate_floatlist(s: Any) -> list[float]: ...
42+
def _validate_marker(s: Any) -> int | str: ...
43+
def _validate_markerlist(s: Any) -> list[int | str]: ...
4244
def validate_fonttype(s: Any) -> int: ...
4345

4446
_auto_backend_sentinel: object

‎lib/matplotlib/tests/test_cycles.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_cycles.py
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def test_marker_cycle():
2727
assert [l.get_marker() for l in ax.lines] == ['.', '*', 'x', '.']
2828

2929

30+
def test_valid_marker_cycles():
31+
fig, ax = plt.subplots()
32+
ax.set_prop_cycle(cycler(marker=[1, "+", ".", 4]))
33+
34+
3035
def test_marker_cycle_kwargs_arrays_iterators():
3136
fig, ax = plt.subplots()
3237
ax.set_prop_cycle(c=np.array(['r', 'g', 'y']),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.