Skip to content

Fix marker validator with cycler (allow mix of classes) #27613

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

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ def validator(s):
validate_float, doc='return a list of floats')


def _validate_marker(s):
try:
return validate_int(s)
except ValueError as e:
try:
return validate_string(s)
except ValueError as e:
raise ValueError('Supported markers are [string, int]') from e


_validate_markerlist = _listify_validator(
_validate_marker, doc='return a list of markers')


def _validate_pathlike(s):
if isinstance(s, (str, os.PathLike)):
# Store value as str because savefig.directory needs to distinguish
Expand Down Expand Up @@ -645,7 +659,7 @@ def _validate_minor_tick_ndivs(n):
'markeredgecolor': validate_colorlist,
'markevery': validate_markeverylist,
'alpha': validate_floatlist,
'marker': validate_stringlist,
'marker': _validate_markerlist,
'hatch': validate_hatchlist,
'dashes': validate_dashlist,
}
Expand Down Expand Up @@ -908,7 +922,7 @@ def _convert_validator_spec(key, conv):
"lines.linewidth": validate_float, # line width in points
"lines.linestyle": _validate_linestyle, # solid line
"lines.color": validate_color, # first color in color cycle
"lines.marker": validate_string, # marker name
"lines.marker": _validate_marker, # marker name
"lines.markerfacecolor": validate_color_or_auto, # default color
"lines.markeredgecolor": validate_color_or_auto, # default color
"lines.markeredgewidth": validate_float,
Expand Down Expand Up @@ -957,7 +971,7 @@ def _convert_validator_spec(key, conv):
"boxplot.meanline": validate_bool,

"boxplot.flierprops.color": validate_color,
"boxplot.flierprops.marker": validate_string,
"boxplot.flierprops.marker": _validate_marker,
"boxplot.flierprops.markerfacecolor": validate_color_or_auto,
"boxplot.flierprops.markeredgecolor": validate_color,
"boxplot.flierprops.markeredgewidth": validate_float,
Expand All @@ -982,7 +996,7 @@ def _convert_validator_spec(key, conv):
"boxplot.medianprops.linestyle": _validate_linestyle,

"boxplot.meanprops.color": validate_color,
"boxplot.meanprops.marker": validate_string,
"boxplot.meanprops.marker": _validate_marker,
"boxplot.meanprops.markerfacecolor": validate_color,
"boxplot.meanprops.markeredgecolor": validate_color,
"boxplot.meanprops.markersize": validate_float,
Expand Down Expand Up @@ -1107,7 +1121,7 @@ def _convert_validator_spec(key, conv):
"axes3d.zaxis.panecolor": validate_color, # 3d background pane

# scatter props
"scatter.marker": validate_string,
"scatter.marker": _validate_marker,
"scatter.edgecolors": validate_string,

"date.epoch": _validate_date,
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/rcsetup.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def validate_int_or_None(s: Any) -> int | None: ...
def validate_float(s: Any) -> float: ...
def validate_float_or_None(s: Any) -> float | None: ...
def validate_floatlist(s: Any) -> list[float]: ...
def _validate_marker(s: Any) -> int | str: ...
def _validate_markerlist(s: Any) -> list[int | str]: ...
def validate_fonttype(s: Any) -> int: ...

_auto_backend_sentinel: object
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/tests/test_cycles.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def test_marker_cycle():
assert [l.get_marker() for l in ax.lines] == ['.', '*', 'x', '.']


def test_valid_marker_cycles():
fig, ax = plt.subplots()
ax.set_prop_cycle(cycler(marker=[1, "+", ".", 4]))


def test_marker_cycle_kwargs_arrays_iterators():
fig, ax = plt.subplots()
ax.set_prop_cycle(c=np.array(['r', 'g', 'y']),
Expand Down