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

Commit843e517

Browse files
committed
GSOD: replace private lines dash info with LineStyle
1 parentca4dfe0 commit843e517

File tree

4 files changed

+86
-100
lines changed

4 files changed

+86
-100
lines changed

‎lib/matplotlib/_enums.py

Lines changed: 69 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -210,22 +210,20 @@ def demo():
210210
'CapStyle':CapStyle.input_description})
211211

212212

213-
def_get_dash_pattern(style):
214-
"""Convert linestyle to dash pattern."""
215-
# import must be local for validator code to live here
216-
from .importrcParams
217-
# un-dashed styles
218-
ifstylein ['solid','None']:
219-
offset=0
220-
dashes=None
221-
# dashed styles
222-
elifstylein ['dashed','dashdot','dotted']:
223-
offset=0
224-
dashes=tuple(rcParams['lines.{}_pattern'.format(style)])
225-
returnoffset,dashes
226-
227-
228-
classLineStyle(Enum):
213+
#: Maps short codes for line style to their full name used by backends.
214+
_ls_mapper= {'-':'solid','--':'dashed','-.':'dashdot',':':'dotted'}
215+
_deprecated_lineStyles= {# hidden names deprecated
216+
'-':'_draw_solid',
217+
'--':'_draw_dashed',
218+
'-.':'_draw_dash_dot',
219+
':':'_draw_dotted',
220+
'None':'_draw_nothing',
221+
' ':'_draw_nothing',
222+
'':'_draw_nothing',
223+
}
224+
225+
226+
classLineStyle(str,_AutoStringNameEnum):
229227
"""
230228
Describe if the line is solid or dashed, and the dash pattern, if any.
231229
@@ -278,25 +276,12 @@ class LineStyle(Enum):
278276
called when using the keyword *dashes* to the cycler , as shown in
279277
:doc:`property_cycle </tutorials/intermediate/color_cycle>`.
280278
"""
281-
solid='-'
282-
dashed='--'
283-
dotted=':'
284-
dashdot='-.'
285-
none='None'
286-
_custom='custom'
287-
288-
_deprecated_lineStyles= {# hidden names deprecated
289-
'-':'_draw_solid',
290-
'--':'_draw_dashed',
291-
'-.':'_draw_dash_dot',
292-
':':'_draw_dotted',
293-
'None':'_draw_nothing',
294-
' ':'_draw_nothing',
295-
'':'_draw_nothing',
296-
}
297-
298-
#: Maps short codes for line style to their full name used by backends.
299-
ls_mapper= {'-':'solid','--':'dashed','-.':'dashdot',':':'dotted'}
279+
solid=auto()
280+
dashed=auto()
281+
dotted=auto()
282+
dashdot=auto()
283+
none=auto()
284+
custom=auto()
300285

301286
def__init__(self,ls,scale=1):
302287
"""
@@ -312,13 +297,14 @@ def __init__(self, ls, scale=1):
312297
factor.
313298
"""
314299

300+
self._linestyle_spec=ls
315301
ifisinstance(ls,str):
316-
iflsin [' ','','none']:
317-
ls='None'
318-
iflsinLineStyle.ls_mapper:
319-
ls=LineStyle.ls_mapper[ls]
302+
iflsin [' ','','None']:
303+
ls='none'
304+
iflsin_ls_mapper:
305+
ls=_ls_mapper[ls]
320306
Enum.__init__(self)
321-
offset,onoffseq=_get_dash_pattern(ls)
307+
offset,onoffseq=None,None
322308
else:
323309
try:
324310
offset,onoffseq=ls
@@ -342,22 +328,45 @@ def __init__(self, ls, scale=1):
342328
ifnotall(isinstance(elem,Number)foreleminonoffseq):
343329
raiseValueError('LineStyle onoffseq must be list of floats.')
344330
self._us_offset=offset
345-
self._us_onoffseq=dashes
346-
self.scale(scale)
347-
348-
@property
349-
defscale(self):
350-
returnself._scale
351-
352-
@scale.setter
353-
defscale(self,s):
354-
ifs<0:
355-
raiseValueError('LineStyle cannot be scaled by a negative value.')
356-
self.offset=self._us_offset*s
357-
self.onoffseq= (
358-
[x*sifxisnotNoneelseNoneforxinself._us_onoffseq]
359-
ifself._us_onoffseqisnotNoneelseNone
360-
)
331+
self._us_onoffseq=onoffseq
332+
333+
defget_dashes(self,lw=1):
334+
"""
335+
Get the (scaled) dash sequence for this `.LineStyle`.
336+
"""
337+
# defer lookup until draw time
338+
ifself._us_offsetisNoneorself._us_onoffseqisNone:
339+
self._us_offset,self._us_onoffseq= \
340+
LineStyle._get_dash_pattern(self.name)
341+
# normalize offset to be positive and shorter than the dash cycle
342+
dsum=sum(self._us_onoffseq)
343+
self._us_offset%=dsum
344+
returnself._scale_dashes(self._us_offset,self._us_onoffseq,lw)
345+
346+
@staticmethod
347+
def_scale_dashes(offset,dashes,lw):
348+
from .importrcParams
349+
ifnotrcParams['lines.scale_dashes']:
350+
returnoffset,dashes
351+
scaled_offset=offset*lw
352+
scaled_dashes= ([x*lwifxisnotNoneelseNoneforxindashes]
353+
ifdashesisnotNoneelseNone)
354+
returnscaled_offset,scaled_dashes
355+
356+
@staticmethod
357+
def_get_dash_pattern(style):
358+
"""Convert linestyle string to explicit dash pattern."""
359+
# import must be local for validator code to live here
360+
from .importrcParams
361+
# un-dashed styles
362+
ifstylein ['solid','None']:
363+
offset=0
364+
dashes=None
365+
# dashed styles
366+
elifstylein ['dashed','dashdot','dotted']:
367+
offset=0
368+
dashes=tuple(rcParams['lines.{}_pattern'.format(style)])
369+
returnoffset,dashes
361370

362371
@staticmethod
363372
deffrom_dashes(seq):
@@ -443,3 +452,7 @@ def plot_linestyles(ax, linestyles, title):
443452

444453
plt.tight_layout()
445454
plt.show()
455+
456+
457+
LineStyle._ls_mapper=_ls_mapper
458+
LineStyle._deprecated_lineStyles=_deprecated_lineStyles

‎lib/matplotlib/lines.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .pathimportPath
1818
from .transformsimport (
1919
Affine2D,Bbox,BboxTransformFrom,BboxTransformTo,TransformedPath)
20-
from ._enumsimportJoinStyle,CapStyle
20+
from ._enumsimportJoinStyle,CapStyle,LineStyle
2121

2222
# Imported here for backward compatibility, even though they don't
2323
# really belong.
@@ -269,7 +269,7 @@ def __init__(self, xdata, ydata,
269269
linewidth=rcParams['lines.linewidth']
270270

271271
iflinestyleisNone:
272-
linestyle=rcParams['lines.linestyle']
272+
linestyle=LineStyle(rcParams['lines.linestyle'])
273273
ifmarkerisNone:
274274
marker=rcParams['lines.marker']
275275
ifmarkerfacecolorisNone:
@@ -308,16 +308,8 @@ def __init__(self, xdata, ydata,
308308
self._drawstyle=None
309309
self._linewidth=linewidth
310310

311-
# scaled dash + offset
312-
self._dashSeq=None
313-
self._dashOffset=0
314-
# unscaled dash + offset
315-
# this is needed scaling the dash pattern by linewidth
316-
self._us_dashSeq=None
317-
self._us_dashOffset=0
318-
319-
self.set_linewidth(linewidth)
320311
self.set_linestyle(linestyle)
312+
self.set_linewidth(linewidth)
321313
self.set_drawstyle(drawstyle)
322314

323315
self._color=None
@@ -739,7 +731,7 @@ def draw(self, renderer):
739731
ifself.get_sketch_params()isnotNone:
740732
gc.set_sketch_params(*self.get_sketch_params())
741733

742-
gc.set_dashes(self._dashOffset,self._dashSeq)
734+
gc.set_dashes(*self._linestyle.get_dashes(self._linewidth))
743735
renderer.draw_path(gc,tpath,affine.frozen())
744736
gc.restore()
745737

@@ -849,7 +841,7 @@ def get_linestyle(self):
849841
850842
See also `~.Line2D.set_linestyle`.
851843
"""
852-
returnself._linestyle
844+
returnself._linestyle._linestyle_spec
853845

854846
defget_linewidth(self):
855847
"""
@@ -1191,7 +1183,7 @@ def set_ydata(self, y):
11911183
defset_dashes(self,seq):
11921184
self.set_linestyle(LineStyle.from_dashes(seq))
11931185

1194-
set_dashes.__doc__=LineStyle.from_dashes.__doc_r
1186+
set_dashes.__doc__=LineStyle.from_dashes.__doc__
11951187

11961188
defupdate_from(self,other):
11971189
"""Copy properties from *other* to self."""
@@ -1204,10 +1196,6 @@ def update_from(self, other):
12041196
self._markerfacecoloralt=other._markerfacecoloralt
12051197
self._markeredgecolor=other._markeredgecolor
12061198
self._markeredgewidth=other._markeredgewidth
1207-
self._dashSeq=other._dashSeq
1208-
self._us_dashSeq=other._us_dashSeq
1209-
self._dashOffset=other._dashOffset
1210-
self._us_dashOffset=other._us_dashOffset
12111199
self._dashcapstyle=other._dashcapstyle
12121200
self._dashjoinstyle=other._dashjoinstyle
12131201
self._solidcapstyle=other._solidcapstyle

‎lib/matplotlib/patches.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
get_parallels,inside_circle,make_wedged_bezier2,
1717
split_bezier_intersecting_with_closedpath,split_path_inout)
1818
from .pathimportPath
19-
from ._enumsimportJoinStyle,CapStyle
19+
from ._enumsimportJoinStyle,CapStyle,LineStyle
2020

2121

2222
@cbook._define_aliases({
@@ -92,8 +92,6 @@ def __init__(self,
9292
else:
9393
self.set_edgecolor(edgecolor)
9494
self.set_facecolor(facecolor)
95-
# unscaled dashes. Needed to scale dash patterns by lw
96-
self._us_dashes=None
9795
self._linewidth=0
9896

9997
self.set_fill(fill)
@@ -254,9 +252,8 @@ def update_from(self, other):
254252
self._fill=other._fill
255253
self._hatch=other._hatch
256254
self._hatch_color=other._hatch_color
257-
# copy the unscaled dash pattern
258-
self._us_dashes=other._us_dashes
259-
self.set_linewidth(other._linewidth)# also sets dash properties
255+
self.set_linestyle(other._linestyle)
256+
self.set_linewidth(other._linewidth)
260257
self.set_transform(other.get_data_transform())
261258
# If the transform of other needs further initialization, then it will
262259
# be the case for this artist too.
@@ -308,7 +305,7 @@ def get_linewidth(self):
308305

309306
defget_linestyle(self):
310307
"""Return the linestyle."""
311-
returnself._linestyle
308+
returnself._linestyle._linestyle_spec
312309

313310
defset_antialiased(self,aa):
314311
"""
@@ -404,10 +401,6 @@ def set_linewidth(self, w):
404401
w=mpl.rcParams['axes.linewidth']
405402

406403
self._linewidth=float(w)
407-
# scale the dash pattern by the linewidth
408-
offset,ls=self._us_dashes
409-
self._dashoffset,self._dashes=mlines._scale_dashes(
410-
offset,ls,self._linewidth)
411404
self.stale=True
412405

413406
defset_linestyle(self,ls):
@@ -438,16 +431,7 @@ def set_linestyle(self, ls):
438431
ls : {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
439432
The line style.
440433
"""
441-
iflsisNone:
442-
ls="solid"
443-
iflsin [' ','','none']:
444-
ls='None'
445-
self._linestyle=ls
446-
# get the unscaled dash pattern
447-
offset,ls=self._us_dashes=mlines._get_dash_pattern(ls)
448-
# scale the dash pattern by the linewidth
449-
self._dashoffset,self._dashes=mlines._scale_dashes(
450-
offset,ls,self._linewidth)
434+
self._linestyle=LineStyle(ls)
451435
self.stale=True
452436

453437
defset_fill(self,b):
@@ -560,10 +544,12 @@ def _bind_draw_path_function(self, renderer):
560544
gc.set_foreground(self._edgecolor,isRGBA=True)
561545

562546
lw=self._linewidth
563-
ifself._edgecolor[3]==0orself._linestyle=='None':
547+
ifself._edgecolor[3]==0orself.get_linestyle()=='None':
564548
lw=0
565549
gc.set_linewidth(lw)
566-
gc.set_dashes(self._dashoffset,self._dashes)
550+
dash_offset,onoffseq=self._linestyle.get_dashes(lw)
551+
# Patch has traditionally ignored the dashoffset.
552+
gc.set_dashes(0,onoffseq)
567553
gc.set_capstyle(self._capstyle)
568554
gc.set_joinstyle(self._joinstyle)
569555

@@ -600,9 +586,7 @@ def draw(self, renderer):
600586
# docstring inherited
601587
ifnotself.get_visible():
602588
return
603-
# Patch has traditionally ignored the dashoffset.
604-
withcbook._setattr_cm(self,_dashoffset=0), \
605-
self._bind_draw_path_function(renderer)asdraw_path:
589+
withself._bind_draw_path_function(renderer)asdraw_path:
606590
path=self.get_path()
607591
transform=self.get_transform()
608592
tpath=transform.transform_path_non_affine(path)

‎lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ def _validate_linestyle(ls):
546546
LineStyle((0,ls))
547547
exceptValueError:
548548
raisee
549+
returnls
549550

550551

551552
validate_fillstyle=ValidateInStrings(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp