From 4cef94528fdb1b65b15faedb014e76a6ca00ad1e Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 12 Sep 2021 16:01:50 +0200 Subject: [PATCH] Support marker="none" to mean "no marker". As for other APIs, this is less likely to be confused with the None object. --- doc/users/next_whats_new/marker_none.rst | 5 +++++ lib/matplotlib/legend_handler.py | 2 +- lib/matplotlib/markers.py | 6 ++++-- lib/matplotlib/tests/test_axes.py | 5 +++-- 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 doc/users/next_whats_new/marker_none.rst diff --git a/doc/users/next_whats_new/marker_none.rst b/doc/users/next_whats_new/marker_none.rst new file mode 100644 index 000000000000..b37f07ea1333 --- /dev/null +++ b/doc/users/next_whats_new/marker_none.rst @@ -0,0 +1,5 @@ +``marker`` can now be set to the string "none" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +... to mean *no-marker*, consistently with other APIs which support the +lowercase version. Using "none" is recommended over using "None", to avoid +confusion with the None object. diff --git a/lib/matplotlib/legend_handler.py b/lib/matplotlib/legend_handler.py index d4876ddc5c6b..6cf6b8ec31c7 100644 --- a/lib/matplotlib/legend_handler.py +++ b/lib/matplotlib/legend_handler.py @@ -566,7 +566,7 @@ def create_artists(self, legend, orig_handle, self.update_prop(legline, plotlines, legend) legline.set_drawstyle('default') - legline.set_marker('None') + legline.set_marker('none') self.update_prop(legline_marker, plotlines, legend) legline_marker.set_linestyle('None') diff --git a/lib/matplotlib/markers.py b/lib/matplotlib/markers.py index 2059e789e2d1..656d225567fb 100644 --- a/lib/matplotlib/markers.py +++ b/lib/matplotlib/markers.py @@ -45,7 +45,8 @@ ``9`` (``CARETRIGHTBASE``) |m34| caretright (centered at base) ``10`` (``CARETUPBASE``) |m35| caretup (centered at base) ``11`` (``CARETDOWNBASE``) |m36| caretdown (centered at base) -``"None"``, ``" "`` or ``""`` nothing +``"none"`` or ``"None"`` nothing +``" "`` or ``""`` nothing ``'$...$'`` |m37| Render the string using mathtext. E.g ``"$f$"`` for marker showing the letter ``f``. @@ -200,6 +201,7 @@ class MarkerStyle: CARETUPBASE: 'caretupbase', CARETDOWNBASE: 'caretdownbase', "None": 'nothing', + "none": 'nothing', None: 'nothing', ' ': 'nothing', '': 'nothing' @@ -227,7 +229,7 @@ def __init__(self, marker=_unset, fillstyle=None): - Another instance of *MarkerStyle* copies the details of that ``marker``. - *None* means no marker. This is the deprecated default. - - For other possible marker values see the module docstring + - For other possible marker values, see the module docstring `matplotlib.markers`. fillstyle : str, default: :rc:`markers.fillstyle` diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 32b0c202478b..8ade7b8b2035 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4117,8 +4117,9 @@ def test_eventplot_orientation(data, orientation): @image_comparison(['marker_styles.png'], remove_text=True) def test_marker_styles(): fig, ax = plt.subplots() - for y, marker in enumerate(sorted(matplotlib.markers.MarkerStyle.markers, - key=lambda x: str(type(x))+str(x))): + for y, marker in enumerate(sorted( + {*matplotlib.markers.MarkerStyle.markers} - {"none"}, + key=lambda x: str(type(x))+str(x))): ax.plot((y % 2)*5 + np.arange(10)*10, np.ones(10)*10*y, linestyle='', marker=marker, markersize=10+y/5, label=marker)