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

Commitdea13f8

Browse files
committed
Allow empty linestyle for collections
1 parentf25c2d0 commitdea13f8

File tree

5 files changed

+128
-99
lines changed

5 files changed

+128
-99
lines changed

‎lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7782,7 +7782,7 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
77827782
raiseTypeError(
77837783
"spy() got an unexpected keyword argument 'linestyle'")
77847784
ret=mlines.Line2D(
7785-
x,y,linestyle='None',marker=marker,markersize=markersize,
7785+
x,y,linestyle='none',marker=marker,markersize=markersize,
77867786
**kwargs)
77877787
self.add_line(ret)
77887788
nr,nc=Z.shape

‎lib/matplotlib/collections.py

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(self,
7979
edgecolors=None,
8080
facecolors=None,
8181
linewidths=None,
82-
linestyles='solid',
82+
linestyles='-',
8383
capstyle=None,
8484
joinstyle=None,
8585
antialiaseds=None,
@@ -105,15 +105,8 @@ def __init__(self,
105105
Face color for each patch making up the collection.
106106
linewidths : float or list of floats, default: :rc:`patch.linewidth`
107107
Line width for each patch making up the collection.
108-
linestyles : str or tuple or list thereof, default: 'solid'
109-
Valid strings are ['solid', 'dashed', 'dashdot', 'dotted', '-',
110-
'--', '-.', ':']. Dash tuples should be of the form::
111-
112-
(offset, onoffseq),
113-
114-
where *onoffseq* is an even length tuple of on and off ink lengths
115-
in points. For examples, see
116-
:doc:`/gallery/lines_bars_and_markers/linestyles`.
108+
linestyles : str or tuple or list thereof, default: '-'
109+
Line style or list of line styles. See `set_linestyle` for details.
117110
capstyle : `.CapStyle`-like, default: :rc:`patch.capstyle`
118111
Style to use for capping lines for all paths in the collection.
119112
Allowed values are %(CapStyle)s.
@@ -584,43 +577,51 @@ def set_linewidth(self, lw):
584577

585578
defset_linestyle(self,ls):
586579
"""
587-
Set thelinestyle(s) for the collection.
580+
Set theline style(s) for the collection.
588581
589-
=========================== =================
590-
linestyle description
591-
=========================== =================
592-
``'-'`` or ``'solid'`` solid line
593-
``'--'`` or ``'dashed'`` dashed line
594-
``'-.'`` or ``'dashdot'`` dash-dotted line
595-
``':'`` or ``'dotted'`` dotted line
596-
=========================== =================
582+
Parameters
583+
----------
584+
ls : str or tuple or list thereof
585+
The line style. Possible values:
597586
598-
Alternatively a dash tuple of the following form can be provided::
587+
- A string:
599588
600-
(offset, onoffseq),
589+
========================================== =================
590+
linestyle description
591+
========================================== =================
592+
``'-'`` or ``'solid'`` solid line
593+
``'--'`` or ``'dashed'`` dashed line
594+
``'-.'`` or ``'dashdot'`` dash-dotted line
595+
``':'`` or ``'dotted'`` dotted line
596+
``'none'``, ``'None'``, ``' '``, or ``''`` draw nothing
597+
========================================== =================
601598
602-
where ``onoffseq`` is an even length tuple of on and off ink in points.
599+
- Alternatively a dash tuple of the following form can be
600+
provided::
603601
604-
Parameters
605-
----------
606-
ls : str or tuple or list thereof
607-
Valid values for individual linestyles include {'-', '--', '-.',
608-
':', '', (offset, on-off-seq)}. See `.Line2D.set_linestyle` for a
609-
complete description.
602+
(offset, onoffseq)
603+
604+
where ``onoffseq`` is an even length tuple of on and off ink
605+
in points.
606+
607+
If a single value is provided, this applies to all objects in the
608+
collection. A list can be provided to set different line styles to
609+
different objects.
610+
611+
For examples see :doc:`/gallery/lines_bars_and_markers/linestyles`.
612+
613+
The ``'dashed'``, ``'dashdot'``, and ''`dotted'`` line styles are
614+
controlled by :rc:`lines.dashed_pattern`,
615+
:rc:`lines.dashdot_pattern`, and :rc:`lines.dotted_pattern`,
616+
respectively.
610617
"""
611-
try:
612-
ifisinstance(ls,str):
613-
ls=cbook.ls_mapper.get(ls,ls)
618+
ifisinstance(ls,str):
619+
dashes= [mlines._get_dash_pattern(ls)]
620+
else:
621+
try:
614622
dashes= [mlines._get_dash_pattern(ls)]
615-
else:
616-
try:
617-
dashes= [mlines._get_dash_pattern(ls)]
618-
exceptValueError:
619-
dashes= [mlines._get_dash_pattern(x)forxinls]
620-
621-
exceptValueErroraserr:
622-
raiseValueError('Do not know how to convert {!r} to '
623-
'dashes'.format(ls))fromerr
623+
exceptValueError:
624+
dashes= [mlines._get_dash_pattern(x)forxinls]
624625

625626
# get the list of raw 'unscaled' dash patterns
626627
self._us_linestyles=dashes
@@ -1522,7 +1523,7 @@ def __init__(self,
15221523
linelength=1,
15231524
linewidth=None,
15241525
color=None,
1525-
linestyle='solid',
1526+
linestyle='-',
15261527
antialiased=None,
15271528
**kwargs
15281529
):
@@ -1545,14 +1546,8 @@ def __init__(self,
15451546
The line width of the event lines, in points.
15461547
color : color or list of colors, default: :rc:`lines.color`
15471548
The color of the event lines.
1548-
linestyle : str or tuple or list thereof, default: 'solid'
1549-
Valid strings are ['solid', 'dashed', 'dashdot', 'dotted',
1550-
'-', '--', '-.', ':']. Dash tuples should be of the form::
1551-
1552-
(offset, onoffseq),
1553-
1554-
where *onoffseq* is an even length tuple of on and off ink
1555-
in points.
1549+
linestyle : str or tuple or list thereof, default: '-'
1550+
Line style or list of line styles. See `set_linestyle` for details.
15561551
antialiased : bool or list thereof, default: :rc:`lines.antialiased`
15571552
Whether to use antialiasing for drawing the lines.
15581553
**kwargs

‎lib/matplotlib/lines.py

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,61 @@
2929
_log=logging.getLogger(__name__)
3030

3131

32-
def_get_dash_pattern(style):
33-
"""Convert linestyle to dash pattern."""
34-
# go from short hand -> full strings
32+
def_get_dash_pattern(style,return_linestyle=False):
33+
"""
34+
Convert linestyle to dash pattern.
35+
36+
Return normalized line style if *return_linestyle* is True.
37+
"""
38+
orig_style=style# keep copy for error message
3539
ifisinstance(style,str):
36-
style=ls_mapper.get(style,style)
40+
# check valid string
41+
_api.check_in_list([*Line2D._lineStyles,*ls_mapper_r],
42+
linestyle=style)
43+
# go from full strings -> short
44+
style=ls_mapper_r.get(style,style)
45+
# normalize empty style
46+
ifstylein ('',' ','None'):
47+
style='none'
48+
ls=style
49+
else:# style is a dash tuple
50+
ls='--'
51+
3752
# un-dashed styles
38-
ifstylein['solid','None']:
53+
ifstylein('-','none'):
3954
offset=0
4055
dashes=None
4156
# dashed styles
42-
elifstylein['dashed','dashdot','dotted']:
57+
elifstylein('--','-.',':'):
4358
offset=0
44-
dashes=tuple(rcParams['lines.{}_pattern'.format(style)])
45-
#
59+
dashes=tuple(rcParams[f'lines.{ls_mapper[style]}_pattern'])
60+
# dash tuple
4661
elifisinstance(style,tuple):
4762
offset,dashes=style
4863
ifoffsetisNone:
49-
raiseValueError(f'Unrecognized linestyle:{style!r}')
64+
raiseValueError(f'Unrecognized linestyle:{orig_style!r}')
5065
else:
51-
raiseValueError(f'Unrecognized linestyle:{style!r}')
66+
raiseValueError(f'Unrecognized linestyle:{orig_style!r}')
5267

5368
# normalize offset to be positive and shorter than the dash cycle
5469
ifdashesisnotNone:
70+
try:
71+
ifany(dash<0.0fordashindashes):
72+
raiseValueError(
73+
"All values in the dash list must be non-negative")
74+
iflen(dashes)andnotany(dash>0.0fordashindashes):
75+
raiseValueError(
76+
'At least one value in the dash list must be positive')
77+
exceptTypeError:
78+
raiseValueError(f'Unrecognized linestyle:{orig_style!r}')
5579
dsum=sum(dashes)
5680
ifdsum:
5781
offset%=dsum
5882

59-
returnoffset,dashes
83+
ifreturn_linestyle:
84+
return (offset,dashes),ls
85+
else:
86+
returnoffset,dashes
6087

6188

6289
def_scale_dashes(offset,dashes,lw):
@@ -223,6 +250,7 @@ class Line2D(Artist):
223250
'-.':'_draw_dash_dot',
224251
':':'_draw_dotted',
225252
'None':'_draw_nothing',
253+
'none':'_draw_nothing',
226254
' ':'_draw_nothing',
227255
'':'_draw_nothing',
228256
}
@@ -1079,12 +1107,12 @@ def set_linewidth(self, w):
10791107

10801108
defset_linestyle(self,ls):
10811109
"""
1082-
Set thelinestyle of the line.
1110+
Set theline style of the line.
10831111
10841112
Parameters
10851113
----------
1086-
ls :{'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
1087-
Possible values:
1114+
ls :str or tuple
1115+
The line style.Possible values:
10881116
10891117
- A string:
10901118
@@ -1107,17 +1135,14 @@ def set_linestyle(self, ls):
11071135
in points. See also :meth:`set_dashes`.
11081136
11091137
For examples see :doc:`/gallery/lines_bars_and_markers/linestyles`.
1138+
1139+
The ``'dashed'``, ``'dashdot'``, and ''`dotted'`` line styles are
1140+
controlled by :rc:`lines.dashed_pattern`,
1141+
:rc:`lines.dashdot_pattern`, and :rc:`lines.dotted_pattern`,
1142+
respectively.
11101143
"""
1111-
ifisinstance(ls,str):
1112-
iflsin [' ','','none']:
1113-
ls='None'
1114-
_api.check_in_list([*self._lineStyles,*ls_mapper_r],ls=ls)
1115-
iflsnotinself._lineStyles:
1116-
ls=ls_mapper_r[ls]
1117-
self._linestyle=ls
1118-
else:
1119-
self._linestyle='--'
1120-
self._unscaled_dash_pattern=_get_dash_pattern(ls)
1144+
self._unscaled_dash_pattern,self._linestyle=_get_dash_pattern(ls,
1145+
True)
11211146
self._dash_pattern=_scale_dashes(
11221147
*self._unscaled_dash_pattern,self._linewidth)
11231148
self.stale=True

‎lib/matplotlib/patches.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(self,
6464
super().__init__()
6565

6666
iflinestyleisNone:
67-
linestyle="solid"
67+
linestyle="-"
6868
ifcapstyleisNone:
6969
capstyle=CapStyle.butt
7070
ifjoinstyleisNone:
@@ -396,35 +396,44 @@ def set_linewidth(self, w):
396396

397397
defset_linestyle(self,ls):
398398
"""
399-
Set the patchlinestyle.
399+
Set the patchline style.
400400
401-
========================================== =================
402-
linestyle description
403-
========================================== =================
404-
``'-'`` or ``'solid'`` solid line
405-
``'--'`` or ``'dashed'`` dashed line
406-
``'-.'`` or ``'dashdot'`` dash-dotted line
407-
``':'`` or ``'dotted'`` dotted line
408-
``'none'``, ``'None'``, ``' '``, or ``''`` draw nothing
409-
========================================== =================
401+
Parameters
402+
----------
403+
ls : str or tuple
404+
The line style. Possible values:
410405
411-
Alternatively a dash tuple of the following form can be provided::
406+
- A string:
412407
413-
(offset, onoffseq)
408+
========================================== =================
409+
linestyle description
410+
========================================== =================
411+
``'-'`` or ``'solid'`` solid line
412+
``'--'`` or ``'dashed'`` dashed line
413+
``'-.'`` or ``'dashdot'`` dash-dotted line
414+
``':'`` or ``'dotted'`` dotted line
415+
``'none'``, ``'None'``, ``' '``, or ``''`` draw nothing
416+
========================================== =================
414417
415-
where ``onoffseq`` is an even length tuple of on and off ink in points.
418+
- Alternatively a dash tuple of the following form can be
419+
provided::
416420
417-
Parameters
418-
----------
419-
ls : {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
420-
The line style.
421+
(offset, onoffseq)
422+
423+
where ``onoffseq`` is an even length tuple of on and off ink
424+
in points.
425+
426+
For examples see :doc:`/gallery/lines_bars_and_markers/linestyles`.
427+
428+
The ``'dashed'``, ``'dashdot'``, and ''`dotted'`` line styles are
429+
controlled by :rc:`lines.dashed_pattern`,
430+
:rc:`lines.dashdot_pattern`, and :rc:`lines.dotted_pattern`,
431+
respectively.
421432
"""
422433
iflsisNone:
423-
ls="solid"
424-
iflsin [' ','','none']:
425-
ls='None'
426-
self._linestyle=ls
427-
self._unscaled_dash_pattern=mlines._get_dash_pattern(ls)
434+
ls="-"
435+
self._unscaled_dash_pattern,self._linestyle= (
436+
mlines._get_dash_pattern(ls,True))
428437
self._dash_pattern=mlines._scale_dashes(
429438
*self._unscaled_dash_pattern,self._linewidth)
430439
self.stale=True
@@ -545,7 +554,7 @@ def _bind_draw_path_function(self, renderer):
545554
gc.set_foreground(self._edgecolor,isRGBA=True)
546555

547556
lw=self._linewidth
548-
ifself._edgecolor[3]==0orself._linestyle=='None':
557+
ifself._edgecolor[3]==0orself._linestyle=='none':
549558
lw=0
550559
gc.set_linewidth(lw)
551560
gc.set_dashes(*self._dash_pattern)

‎lib/matplotlib/tests/test_patches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ def test_default_linestyle():
797797
patch=Patch()
798798
patch.set_linestyle('--')
799799
patch.set_linestyle(None)
800-
assertpatch.get_linestyle()=='solid'
800+
assertpatch.get_linestyle()=='-'
801801

802802

803803
deftest_default_capstyle():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp