Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ded4951

Browse files
authored
Merge pull request #21074 from anntzer/msn2
Deprecate MarkerStyle(None).
2 parents 4d6ab93 + 20d92cc commit ded4951

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Calling ``MarkerStyle()`` with no arguments
2-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1+
Calling ``MarkerStyle()`` with no arguments or ``MarkerStyle(None)``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33
... is deprecated; use ``MarkerStyle("")`` to construct an empty marker style.

lib/matplotlib/lines.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ def __init__(self, xdata, ydata,
368368

369369
self._color = None
370370
self.set_color(color)
371+
if marker is None:
372+
marker = 'none' # Default.
371373
self._marker = MarkerStyle(marker, fillstyle)
372374

373375
self._markevery = None

lib/matplotlib/markers.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@
6464
rotated by ``angle``.
6565
============================== ====== =========================================
6666
67-
``None`` also means 'nothing' when directly constructing a `.MarkerStyle`, but
68-
note that there are other contexts where ``marker=None`` instead means "the
69-
default marker" (e.g. :rc:`scatter.marker` for `.Axes.scatter`).
67+
As a deprecated feature, ``None`` also means 'nothing' when directly
68+
constructing a `.MarkerStyle`, but note that there are other contexts where
69+
``marker=None`` instead means "the default marker" (e.g. :rc:`scatter.marker`
70+
for `.Axes.scatter`).
7071
7172
Note that special symbols can be defined via the
7273
:doc:`STIX math font </tutorials/text/mathtext>`,
@@ -202,7 +203,6 @@ class MarkerStyle:
202203
CARETDOWNBASE: 'caretdownbase',
203204
"None": 'nothing',
204205
"none": 'nothing',
205-
None: 'nothing',
206206
' ': 'nothing',
207207
'': 'nothing'
208208
}
@@ -245,6 +245,12 @@ def __init__(self, marker=_unset, fillstyle=None):
245245
"deprecated since %(since)s; support will be removed "
246246
"%(removal)s. Use MarkerStyle('') to construct an empty "
247247
"MarkerStyle.")
248+
if marker is None:
249+
marker = ""
250+
_api.warn_deprecated(
251+
"3.6", message="MarkerStyle(None) is deprecated since "
252+
"%(since)s; support will be removed %(removal)s. Use "
253+
"MarkerStyle('') to construct an empty MarkerStyle.")
248254
self._set_marker(marker)
249255

250256
__init__.__signature__ = inspect.signature( # Only for deprecation period.

lib/matplotlib/tests/test_axes.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4117,9 +4117,15 @@ def test_eventplot_orientation(data, orientation):
41174117
@image_comparison(['marker_styles.png'], remove_text=True)
41184118
def test_marker_styles():
41194119
fig, ax = plt.subplots()
4120-
for y, marker in enumerate(sorted(
4121-
{*matplotlib.markers.MarkerStyle.markers} - {"none"},
4122-
key=lambda x: str(type(x))+str(x))):
4120+
# Since generation of the test image, None was removed but 'none' was
4121+
# added. By moving 'none' to the front (=former sorted place of None)
4122+
# we can avoid regenerating the test image. This can be removed if the
4123+
# test image has to be regenerated for other reasons.
4124+
markers = sorted(matplotlib.markers.MarkerStyle.markers,
4125+
key=lambda x: str(type(x))+str(x))
4126+
markers.remove('none')
4127+
markers = ['none', *markers]
4128+
for y, marker in enumerate(markers):
41234129
ax.plot((y % 2)*5 + np.arange(10)*10, np.ones(10)*10*y, linestyle='',
41244130
marker=marker, markersize=10+y/5, label=marker)
41254131

lib/matplotlib/tests/test_marker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def test_marker_fillstyle():
1919
'x',
2020
'',
2121
'None',
22-
None,
2322
r'$\frac{1}{2}$',
2423
"$\u266B$",
2524
1,
@@ -40,10 +39,13 @@ def test_markers_valid(marker):
4039
markers.MarkerStyle(marker)
4140

4241

43-
def test_deprecated_marker_noargs():
42+
def test_deprecated_marker():
4443
with pytest.warns(MatplotlibDeprecationWarning):
4544
ms = markers.MarkerStyle()
4645
markers.MarkerStyle(ms) # No warning on copy.
46+
with pytest.warns(MatplotlibDeprecationWarning):
47+
ms = markers.MarkerStyle(None)
48+
markers.MarkerStyle(ms) # No warning on copy.
4749

4850

4951
@pytest.mark.parametrize('marker', [

0 commit comments

Comments
 (0)