From 958cfbb3372aeba679bd0ca282f7ed9c9b6aa0e9 Mon Sep 17 00:00:00 2001 From: lvr44 Date: Mon, 29 May 2023 16:59:12 -0300 Subject: [PATCH 1/3] More consistent handling of 'None' vs. 'none' --- lib/matplotlib/axes/_axes.py | 4 ++-- lib/matplotlib/axes/_base.py | 2 +- lib/matplotlib/backends/qt_editor/figureoptions.py | 3 ++- lib/matplotlib/legend_handler.py | 2 +- lib/matplotlib/lines.py | 9 +++++---- lib/matplotlib/patches.py | 4 ++-- lib/matplotlib/rcsetup.py | 2 +- lib/matplotlib/tests/test_axes.py | 2 +- lib/matplotlib/tests/test_legend.py | 2 +- lib/matplotlib/tri/_triplot.py | 4 ++-- lib/mpl_toolkits/mplot3d/axes3d.py | 2 +- 11 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 5369eadbdefd..4454b9254869 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -2134,7 +2134,7 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none, b = self.axhline(**kwargs) else: kwargs.setdefault('marker', 'o') - kwargs.setdefault('linestyle', 'None') + kwargs.setdefault('linestyle', 'none') a, = self.plot(lags, correls, **kwargs) b = None return lags, correls, a, b @@ -8080,7 +8080,7 @@ def spy(self, Z, precision=0, marker=None, markersize=None, if 'linestyle' in kwargs: raise _api.kwarg_error("spy", "linestyle") ret = mlines.Line2D( - x, y, linestyle='None', marker=marker, markersize=markersize, + x, y, linestyle='none', marker=marker, markersize=markersize, **kwargs) self.add_line(ret) nr, nc = Z.shape diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index fb04d917720f..315f8e91fe24 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -201,7 +201,7 @@ def _process_plot_format(fmt, *, ambiguous_fmt_datakey=False): if linestyle is None and marker is None: linestyle = mpl.rcParams['lines.linestyle'] if linestyle is None: - linestyle = 'None' + linestyle = 'none' if marker is None: marker = 'None' diff --git a/lib/matplotlib/backends/qt_editor/figureoptions.py b/lib/matplotlib/backends/qt_editor/figureoptions.py index c744ccc3ca59..23680b6c9dd9 100644 --- a/lib/matplotlib/backends/qt_editor/figureoptions.py +++ b/lib/matplotlib/backends/qt_editor/figureoptions.py @@ -15,7 +15,8 @@ '--': 'Dashed', '-.': 'DashDot', ':': 'Dotted', - 'None': 'None', + 'None': 'none', + 'none': 'none' } DRAWSTYLES = { diff --git a/lib/matplotlib/legend_handler.py b/lib/matplotlib/legend_handler.py index 8aad6ce5219c..046ae36764cc 100644 --- a/lib/matplotlib/legend_handler.py +++ b/lib/matplotlib/legend_handler.py @@ -572,7 +572,7 @@ def create_artists(self, legend, orig_handle, legline.set_marker('none') self.update_prop(legline_marker, plotlines, legend) - legline_marker.set_linestyle('None') + legline_marker.set_linestyle('none') if legend.markerscale != 1: newsz = legline_marker.get_markersize() * legend.markerscale diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index 8b6c3669b967..37028e5800c5 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -36,7 +36,7 @@ def _get_dash_pattern(style): if isinstance(style, str): style = ls_mapper.get(style, style) # un-dashed styles - if style in ['solid', 'None']: + if style in ['solid', 'none', 'None']: offset = 0 dashes = None # dashed styles @@ -240,6 +240,7 @@ class Line2D(Artist): '-.': '_draw_dash_dot', ':': '_draw_dotted', 'None': '_draw_nothing', + 'none': '_draw_nothing', ' ': '_draw_nothing', '': '_draw_nothing', } @@ -476,7 +477,7 @@ def contains(self, mouseevent): # the error flags accordingly. with np.errstate(all='ignore'): # Check for collision - if self._linestyle in ['None', None]: + if self._linestyle in ['none', 'None', None]: # If no line, return the nearby point(s) ind, = np.nonzero( (xt - mouseevent.x) ** 2 + (yt - mouseevent.y) ** 2 @@ -1168,8 +1169,8 @@ def set_linestyle(self, ls): For examples see :doc:`/gallery/lines_bars_and_markers/linestyles`. """ if isinstance(ls, str): - if ls in [' ', '', 'none']: - ls = 'None' + if ls in [' ', '', 'None']: + ls = 'none' _api.check_in_list([*self._lineStyles, *ls_mapper_r], ls=ls) if ls not in self._lineStyles: ls = ls_mapper_r[ls] diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index a3c51e7bfa00..00a603525f33 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -421,8 +421,8 @@ def set_linestyle(self, ls): """ if ls is None: ls = "solid" - if ls in [' ', '', 'none']: - ls = 'None' + if ls in [' ', '', 'None']: + ls = 'none' self._linestyle = ls self._unscaled_dash_pattern = mlines._get_dash_pattern(ls) self._dash_pattern = mlines._scale_dashes( diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 663ff4b70536..ab35054d4e60 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -348,7 +348,7 @@ def validate_aspect(s): def validate_fontsize_None(s): - if s is None or s == 'None': + if s is None or s == 'None' or s == 'none': return None else: return validate_fontsize(s) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 51d29ecf8b0b..d108cd618485 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -3939,7 +3939,7 @@ def test_errorbar_line_specific_kwargs(): x = np.arange(5) y = np.arange(5) - plotline, _, _ = plt.errorbar(x, y, xerr=1, yerr=1, ls='None', + plotline, _, _ = plt.errorbar(x, y, xerr=1, yerr=1, ls='none', marker='s', fillstyle='full', drawstyle='steps-mid', dash_capstyle='round', diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index c94a0f5f6169..117dfb795a05 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -1201,7 +1201,7 @@ def test_legend_markers_from_line2d(): # Test that markers can be copied for legend lines (#17960) _markers = ['.', '*', 'v'] fig, ax = plt.subplots() - lines = [mlines.Line2D([0], [0], ls='None', marker=mark) + lines = [mlines.Line2D([0], [0], ls='none', marker=mark) for mark in _markers] labels = ["foo", "bar", "xyzzy"] markers = [line.get_marker() for line in lines] diff --git a/lib/matplotlib/tri/_triplot.py b/lib/matplotlib/tri/_triplot.py index 6168946b1531..6ba91c637cf3 100644 --- a/lib/matplotlib/tri/_triplot.py +++ b/lib/matplotlib/tri/_triplot.py @@ -63,7 +63,7 @@ def triplot(ax, *args, **kwargs): 'marker': 'None', # No marker to draw. 'zorder': kw.get('zorder', 1), # Path default zorder is used. } - if linestyle not in [None, 'None', '', ' ']: + if linestyle not in [None, 'None', 'none', '', ' ']: tri_lines_x = np.insert(x[edges], 2, np.nan, axis=1) tri_lines_y = np.insert(y[edges], 2, np.nan, axis=1) tri_lines = ax.plot(tri_lines_x.ravel(), tri_lines_y.ravel(), @@ -75,7 +75,7 @@ def triplot(ax, *args, **kwargs): marker = kw['marker'] kw_markers = { **kw, - 'linestyle': 'None', # No line to draw. + 'linestyle': 'none', # No line to draw. } kw_markers.pop('label', None) if marker not in [None, 'None', '', ' ']: diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index cf2722eb4aae..92787fbf8c57 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -3048,7 +3048,7 @@ def errorbar(self, x, y, z, zerr=None, yerr=None, xerr=None, fmt='', eb_lines_style[key] = kwargs[key] # Make the style dict for caps (the "hats"). - eb_cap_style = {**base_style, 'linestyle': 'None'} + eb_cap_style = {**base_style, 'linestyle': 'none'} if capsize is None: capsize = mpl.rcParams["errorbar.capsize"] if capsize > 0: From e962eadf80a5fdd5f36122764890c3d4526d1da5 Mon Sep 17 00:00:00 2001 From: lvr44 Date: Mon, 29 May 2023 19:06:32 -0300 Subject: [PATCH 2/3] update test in test_axes.py --- lib/matplotlib/tests/test_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index d108cd618485..b50e917a342b 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4178,7 +4178,7 @@ def _assert_equal(stem_container, linecolor=None, markercolor=None, markercolor) if marker is not None: assert stem_container.markerline.get_marker() == marker - assert stem_container.markerline.get_linestyle() == 'None' + assert stem_container.markerline.get_linestyle() == 'none' fig, ax = plt.subplots() From bb9c6c5bd20896e79f4ed0c485f71ab4ef019679 Mon Sep 17 00:00:00 2001 From: lvr44 Date: Mon, 29 May 2023 19:36:02 -0300 Subject: [PATCH 3/3] fixing errors on tests --- lib/matplotlib/axes/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 315f8e91fe24..fb04d917720f 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -201,7 +201,7 @@ def _process_plot_format(fmt, *, ambiguous_fmt_datakey=False): if linestyle is None and marker is None: linestyle = mpl.rcParams['lines.linestyle'] if linestyle is None: - linestyle = 'none' + linestyle = 'None' if marker is None: marker = 'None'