Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4a33c4f

Browse files
committed
Deprecate support for no-args MarkerStyle().
As noted in the module docstring, there is a confusion between using ageneric default MarkerStyle (empty) and the artist-specific one (e.g.scatter plots use `rcParams["scatter.marker"]`). Fortunately, directconstruction of MarkerStyles (especially of empty ones) is hardly everneeded, so we can just make the parameter required.
1 parent65cf35b commit4a33c4f

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
fromcollections.abcimportSized
130+
importinspect
130131

131132
importnumpyasnp
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+
ifmarkerisself._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+
lambdaself,marker,fillstyle=None:None)
249+
237250
def_recache(self):
238251
ifself._marker_functionisNone:
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
importnumpyasnp
22
importmatplotlib.pyplotasplt
33
frommatplotlibimportmarkers
4+
frommatplotlib._api.deprecationimportMatplotlibDeprecationWarning
45
frommatplotlib.pathimportPath
56
frommatplotlib.testing.decoratorsimportcheck_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
deftest_markers_valid(marker):
3939
# Checking this doesn't fail.
4040
markers.MarkerStyle(marker)
4141

4242

43+
deftest_deprecated_marker_noargs():
44+
withpytest.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)

[8]ページ先頭

©2009-2025 Movatter.jp