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

Skip to content

Commit 4a33c4f

Browse files
committed
Deprecate support for no-args MarkerStyle().
As noted in the module docstring, there is a confusion between using a generic default MarkerStyle (empty) and the artist-specific one (e.g. scatter plots use `rcParams["scatter.marker"]`). Fortunately, direct construction of MarkerStyles (especially of empty ones) is hardly ever needed, so we can just make the parameter required.
1 parent 65cf35b commit 4a33c4f

File tree

3 files changed

+26
-4
lines changed

3 files changed

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

lib/matplotlib/markers.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"""
128128

129129
from collections.abc import Sized
130+
import inspect
130131

131132
import numpy as np
132133

@@ -216,14 +217,16 @@ class MarkerStyle:
216217
# TODO: Is this ever used as a non-constant?
217218
_point_size_reduction = 0.5
218219

219-
def __init__(self, marker=None, fillstyle=None):
220+
_unset = object() # For deprecation of MarkerStyle(<noargs>).
221+
222+
def __init__(self, marker=_unset, fillstyle=None):
220223
"""
221224
Parameters
222225
----------
223-
marker : str, array-like, Path, MarkerStyle, or None, default: None
226+
marker : str, array-like, Path, MarkerStyle, or None
224227
- Another instance of *MarkerStyle* copies the details of that
225228
``marker``.
226-
- *None* means no marker.
229+
- *None* means no marker. This is the deprecated default.
227230
- For other possible marker values see the module docstring
228231
`matplotlib.markers`.
229232
@@ -232,8 +235,18 @@ def __init__(self, marker=None, fillstyle=None):
232235
"""
233236
self._marker_function = None
234237
self._set_fillstyle(fillstyle)
238+
# Remove _unset and signature rewriting after deprecation elapses.
239+
if marker is self._unset:
240+
marker = ""
241+
_api.warn_deprecated(
242+
"3.6", message="Calling MarkerStyle() with no parameters is "
243+
"deprecated %(since)s; support will be removed %(removal)s. "
244+
"Use MarkerStyle('') to construct an empty MarkerStyle.")
235245
self._set_marker(marker)
236246

247+
__init__.__signature__ = inspect.signature( # Only for deprecation period.
248+
lambda self, marker, fillstyle=None: None)
249+
237250
def _recache(self):
238251
if self._marker_function is None:
239252
return

lib/matplotlib/tests/test_marker.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import matplotlib.pyplot as plt
33
from matplotlib import markers
4+
from matplotlib._api.deprecation import MatplotlibDeprecationWarning
45
from matplotlib.path import Path
56
from matplotlib.testing.decorators import check_figures_equal
67

@@ -32,14 +33,19 @@ def test_marker_fillstyle():
3233
(5, 0, 10), # a pentagon, rotated by 10 degrees
3334
(7, 1, 10), # a 7-pointed star, rotated by 10 degrees
3435
(5, 2, 10), # asterisk, rotated by 10 degrees
35-
markers.MarkerStyle(),
3636
markers.MarkerStyle('o'),
3737
])
3838
def test_markers_valid(marker):
3939
# Checking this doesn't fail.
4040
markers.MarkerStyle(marker)
4141

4242

43+
def test_deprecated_marker_noargs():
44+
with pytest.warns(MatplotlibDeprecationWarning):
45+
ms = markers.MarkerStyle()
46+
markers.MarkerStyle(ms) # No warning on copy.
47+
48+
4349
@pytest.mark.parametrize('marker', [
4450
'square', # arbitrary string
4551
np.array([[-0.5, 0, 1, 2, 3]]), # 1D array

0 commit comments

Comments
 (0)