Skip to content

More consistent handling of 'None' vs. 'none' #26004

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/qt_editor/figureoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
'--': 'Dashed',
'-.': 'DashDot',
':': 'Dotted',
'None': 'None',
'None': 'none',
'none': 'none'
}

DRAWSTYLES = {
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/legend_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -240,6 +240,7 @@ class Line2D(Artist):
'-.': '_draw_dash_dot',
':': '_draw_dotted',
'None': '_draw_nothing',
'none': '_draw_nothing',
' ': '_draw_nothing',
'': '_draw_nothing',
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tri/_triplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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', '', ' ']:
Expand Down
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down