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

Commiteb76378

Browse files
committed
Deprecate support for dash-offset = None.
e.g. `plot([1, 2], ls=(None, (4, 4)))` which was previously a synonymfor `plot([1, 2], ls=(0, (4, 4)))` which means "dash-pattern of4pt-long dashes separated by 4pt spaces, with an offset of 0pt atstart".Passing None instead of 0 was already not (likely, never) supported forpdf, ps, or svg (an exception is raised at savefig() time for ps/svg, aninvalid pdf is generated). There isn't much of a point in supportingNone (this also makes e.g. mplcairo more complex because of statictyping in C++ extensions), so just deprecate it.
1 parent32d3306 commiteb76378

File tree

9 files changed

+47
-23
lines changed

9 files changed

+47
-23
lines changed

‎doc/api/next_api_changes/deprecations.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,12 @@ method consistent across all artists; thus, additional parameters to
264264
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
265265
This method is deprecated. `.DraggableBase.on_motion` now handles both the
266266
blitting and the non-blitting cases.
267+
268+
Passing the dash offset as None
269+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
270+
Fine control of dash patterns can be achieved by passing an ``(offset,
271+
(on-length, off-length, on-length, off-length, ...))`` pair as the linestyle
272+
property of `.Line2D` and `.LineCollection`. Previously, certain APIs would
273+
accept ``offset = None`` as a synonym for ``offset = 0``, but this was never
274+
universally implemented, e.g. for vector output. Support for ``offset = None``
275+
is deprecated, set the offset to 0 instead.

‎examples/text_labels_and_annotations/legend_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def create_artists(self, legend, orig_handle,
153153
lw=orig_handle.get_linewidths()[i]
154154
exceptIndexError:
155155
lw=orig_handle.get_linewidths()[0]
156-
ifdashes[0]isnotNone:
156+
ifdashes[1]isnotNone:
157157
legline.set_dashes(dashes[1])
158158
legline.set_color(color)
159159
legline.set_transform(trans)

‎lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ def __init__(self):
711711
self._capstyle='butt'
712712
self._cliprect=None
713713
self._clippath=None
714-
self._dashes=None,None
714+
self._dashes=0,None
715715
self._joinstyle='round'
716716
self._linestyle='solid'
717717
self._linewidth=1

‎lib/matplotlib/collections.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def __init__(self,
115115
cm.ScalarMappable.__init__(self,norm,cmap)
116116
# list of un-scaled dash patterns
117117
# this is needed scaling the dash pattern by linewidth
118-
self._us_linestyles= [(None,None)]
118+
self._us_linestyles= [(0,None)]
119119
# list of dash patterns
120-
self._linestyles= [(None,None)]
120+
self._linestyles= [(0,None)]
121121
# list of unbroadcast/scaled linewidths
122122
self._us_lw= [0]
123123
self._linewidths= [0]
@@ -333,7 +333,7 @@ def draw(self, renderer):
333333
if (len(paths)==1andlen(trans)<=1and
334334
len(facecolors)==1andlen(edgecolors)==1and
335335
len(self._linewidths)==1and
336-
self._linestyles== [(None,None)]and
336+
all(ls[1]isNoneforlsinself._linestyles)and
337337
len(self._antialiaseds)==1andlen(self._urls)==1and
338338
self.get_hatch()isNone):
339339
iflen(trans):

‎lib/matplotlib/lines.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,26 @@ def _get_dash_pattern(style):
3838
style=ls_mapper.get(style,style)
3939
# un-dashed styles
4040
ifstylein ['solid','None']:
41-
offset,dashes=None,None
41+
offset=0
42+
dashes=None
4243
# dashed styles
4344
elifstylein ['dashed','dashdot','dotted']:
4445
offset=0
4546
dashes=tuple(rcParams['lines.{}_pattern'.format(style)])
4647
#
4748
elifisinstance(style,tuple):
4849
offset,dashes=style
50+
ifoffsetisNone:
51+
cbook.warn_deprecated(
52+
"3.3",message="Passing the dash offset as None is deprecated "
53+
"since %(since)s and support for it will be removed "
54+
"%(removal)s; pass it as zero instead.")
55+
offset=0
4956
else:
5057
raiseValueError('Unrecognized linestyle: %s'%str(style))
5158

5259
# normalize offset to be positive and shorter than the dash cycle
53-
ifdashesisnotNoneandoffsetisnotNone:
60+
ifdashesisnotNone:
5461
dsum=sum(dashes)
5562
ifdsum:
5663
offset%=dsum
@@ -61,14 +68,9 @@ def _get_dash_pattern(style):
6168
def_scale_dashes(offset,dashes,lw):
6269
ifnotrcParams['lines.scale_dashes']:
6370
returnoffset,dashes
64-
65-
scaled_offset=scaled_dashes=None
66-
ifoffsetisnotNone:
67-
scaled_offset=offset*lw
68-
ifdashesisnotNone:
69-
scaled_dashes= [x*lwifxisnotNoneelseNone
70-
forxindashes]
71-
71+
scaled_offset=offset*lw
72+
scaled_dashes= ([x*lwifxisnotNoneelseNoneforxindashes]
73+
ifdashesisnotNoneelseNone)
7274
returnscaled_offset,scaled_dashes
7375

7476

‎lib/matplotlib/rcsetup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,18 @@ def _is_iterable_not_string_like(x):
579579
and_is_iterable_not_string_like(ls[1])
580580
andlen(ls[1])%2==0
581581
andall(isinstance(elem,Number)foreleminls[1])):
582+
ifls[0]isNone:
583+
cbook.warn_deprecated(
584+
"3.3",message="Passing the dash offset as None is deprecated "
585+
"since %(since)s and support for it will be removed "
586+
"%(removal)s; pass it as zero instead.")
587+
ls= (0,ls[1])
582588
returnls
583589
# For backcompat: (on, off, on, off, ...); the offset is implicitly None.
584590
if (_is_iterable_not_string_like(ls)
585591
andlen(ls)%2==0
586592
andall(isinstance(elem,Number)foreleminls)):
587-
return (None,ls)
593+
return (0,ls)
588594
raiseValueError(f"linestyle{ls!r} is not a valid on-off ink sequence.")
589595

590596

‎lib/matplotlib/tests/test_collections.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test__EventCollection__get_props():
7777
# check that the default lineoffset matches the input lineoffset
7878
assertprops['lineoffset']==coll.get_lineoffset()
7979
# check that the default linestyle matches the input linestyle
80-
assertcoll.get_linestyle()== [(None,None)]
80+
assertcoll.get_linestyle()== [(0,None)]
8181
# check that the default color matches the input color
8282
forcolorin [coll.get_color(),*coll.get_colors()]:
8383
np.testing.assert_array_equal(color,props['color'])
@@ -501,11 +501,11 @@ def test_lslw_bcast():
501501
col.set_linestyles(['-','-'])
502502
col.set_linewidths([1,2,3])
503503

504-
assertcol.get_linestyles()== [(None,None)]*6
504+
assertcol.get_linestyles()== [(0,None)]*6
505505
assertcol.get_linewidths()== [1,2,3]*2
506506

507507
col.set_linestyles(['-','-','-'])
508-
assertcol.get_linestyles()== [(None,None)]*3
508+
assertcol.get_linestyles()== [(0,None)]*3
509509
assert (col.get_linewidths()== [1,2,3]).all()
510510

511511

‎lib/matplotlib/tests/test_rcparams.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,9 @@ def generate_validator_testcases(valid):
370370
('',''), (' ',' '),
371371
('None','none'), ('none','none'),
372372
('DoTtEd','dotted'),# case-insensitive
373-
('1, 3', (None, (1,3))),
374-
([1.23,456], (None, [1.23,456.0])),
375-
([1,2,3,4], (None, [1.0,2.0,3.0,4.0])),
376-
((None, [1,2]), (None, [1,2])),
373+
('1, 3', (0, (1,3))),
374+
([1.23,456], (0, [1.23,456.0])),
375+
([1,2,3,4], (0, [1.0,2.0,3.0,4.0])),
377376
((0, [1,2]), (0, [1,2])),
378377
((-1, [1,2]), (-1, [1,2])),
379378
),

‎src/py_converters.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ int convert_dashes(PyObject *dashobj, void *dashesp)
237237
if (PyErr_Occurred()) {
238238
return0;
239239
}
240+
}else {
241+
if (PyErr_WarnEx(PyExc_FutureWarning,
242+
"Passing the dash offset as None is deprecated since"
243+
"Matplotlib 3.3 and will be removed in Matplotlib 3.5;"
244+
"pass it as zero instead.",
245+
1)) {
246+
return0;
247+
}
240248
}
241249

242250
if (dashes_seq == Py_None) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp