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

Skip to content

Commit 04ffd42

Browse files
committed
Fix #5917. New dash patterns. Scale dashes by lw
1 parent 2a4863c commit 04ffd42

File tree

5 files changed

+44
-31
lines changed

5 files changed

+44
-31
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -771,14 +771,6 @@ class GraphicsContextBase(object):
771771
An abstract base class that provides color, line styles, etc...
772772
"""
773773

774-
# a mapping from dash styles to suggested offset, dash pairs
775-
dashd = {
776-
'solid': (None, None),
777-
'dashed': (0, (6.0, 6.0)),
778-
'dashdot': (0, (3.0, 5.0, 1.0, 5.0)),
779-
'dotted': (0, (1.0, 3.0)),
780-
}
781-
782774
def __init__(self):
783775
self._alpha = 1.0
784776
self._forced_alpha = False # if True, _alpha overrides A from RGBA
@@ -870,7 +862,16 @@ def get_dashes(self):
870862
871863
Default value is None
872864
"""
873-
return self._dashes
865+
if rcParams['_internal.classic_mode']:
866+
return self._dashes
867+
else:
868+
scale = max(1.0, self.get_linewidth())
869+
offset, dashes = self._dashes
870+
if offset is not None:
871+
offset = offset * scale
872+
if dashes is not None:
873+
dashes = [x * scale for x in dashes]
874+
return offset, dashes
874875

875876
def get_forced_alpha(self):
876877
"""
@@ -1047,17 +1048,17 @@ def set_linewidth(self, w):
10471048
def set_linestyle(self, style):
10481049
"""
10491050
Set the linestyle to be one of ('solid', 'dashed', 'dashdot',
1050-
'dotted'). One may specify customized dash styles by providing
1051-
a tuple of (offset, dash pairs). For example, the predefiend
1052-
linestyles have following values.:
1053-
1054-
'dashed' : (0, (6.0, 6.0)),
1055-
'dashdot' : (0, (3.0, 5.0, 1.0, 5.0)),
1056-
'dotted' : (0, (1.0, 3.0)),
1051+
'dotted'). These are defined in the rcParams
1052+
`lines.dashed_pattern`, `lines.dashdot_pattern` and
1053+
`lines.dotted_pattern`. One may also specify customized dash
1054+
styles by providing a tuple of (offset, dash pairs).
10571055
"""
10581056

1059-
if style in self.dashd:
1060-
offset, dashes = self.dashd[style]
1057+
if style == 'solid':
1058+
offset, dashes = None, None
1059+
elif style in ['dashed', 'dashdot', 'dotted']:
1060+
offset = 0
1061+
dashes = rcParams['lines.{}_pattern'.format(style)]
10611062
elif isinstance(style, tuple):
10621063
offset, dashes = style
10631064
else:

lib/matplotlib/mpl-data/stylelib/classic.mplstyle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ lines.dash_capstyle : butt # butt|round|projecting
1515
lines.solid_joinstyle : round # miter|round|bevel
1616
lines.solid_capstyle : projecting # butt|round|projecting
1717
lines.antialiased : True # render lines in antialiased (no jaggies)
18+
lines.dashed_pattern : 6, 6
19+
lines.dashdot_pattern : 3, 5, 1, 5
20+
lines.dotted_pattern : 1, 3
1821

1922
### Marker props
2023
markers.fillstyle: full

lib/matplotlib/rcsetup.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,18 @@ def validate_maskedarray(v):
275275

276276

277277
class validate_nseq_float(object):
278-
def __init__(self, n):
278+
def __init__(self, n=None):
279279
self.n = n
280280

281281
def __call__(self, s):
282282
"""return a seq of n floats or raise"""
283283
if isinstance(s, six.string_types):
284-
s = s.split(',')
284+
s = [x.strip() for x in s.split(',')]
285285
err_msg = _str_err_msg
286286
else:
287287
err_msg = _seq_err_msg
288288

289-
if len(s) != self.n:
289+
if self.n is not None and len(s) != self.n:
290290
raise ValueError(err_msg.format(n=self.n, num=len(s), s=s))
291291

292292
try:
@@ -296,18 +296,18 @@ def __call__(self, s):
296296

297297

298298
class validate_nseq_int(object):
299-
def __init__(self, n):
299+
def __init__(self, n=None):
300300
self.n = n
301301

302302
def __call__(self, s):
303303
"""return a seq of n ints or raise"""
304304
if isinstance(s, six.string_types):
305-
s = s.split(',')
305+
s = [x.strip() for x in s.split(',')]
306306
err_msg = _str_err_msg
307307
else:
308308
err_msg = _seq_err_msg
309309

310-
if len(s) != self.n:
310+
if self.n is not None and len(s) != self.n:
311311
raise ValueError(err_msg.format(n=self.n, num=len(s), s=s))
312312

313313
try:
@@ -836,6 +836,9 @@ def validate_hist_bins(s):
836836
'lines.solid_joinstyle': ['round', validate_joinstyle],
837837
'lines.dash_capstyle': ['butt', validate_capstyle],
838838
'lines.solid_capstyle': ['projecting', validate_capstyle],
839+
'lines.dashed_pattern': [[2.8, 1.2], validate_nseq_float()],
840+
'lines.dashdot_pattern': [[4.8, 1.2, 0.8, 1.2], validate_nseq_float()],
841+
'lines.dotted_pattern': [[1.2, 0.6], validate_nseq_float()],
839842

840843
# marker props
841844
'markers.fillstyle': ['full', validate_fillstyle],
@@ -992,14 +995,15 @@ def validate_hist_bins(s):
992995
'axes.formatter.use_mathtext': [False, validate_bool],
993996
'axes.formatter.useoffset': [True, validate_bool],
994997
'axes.unicode_minus': [True, validate_bool],
995-
'axes.color_cycle': [['b', 'g', 'r', 'c', 'm', 'y', 'k'],
996-
deprecate_axes_colorcycle], # cycle of plot
997-
# line colors
998-
# This entry can be either a cycler object or a
998+
'axes.prop_cycle': [
999+
ccycler('color',
1000+
['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728',
1001+
'#9467bd', '#8c564b', '#e377c2', '#7f7f7f',
1002+
'#bcbd22', '#17becf']),
1003+
validate_cycler], # This entry can be either a cycler object or a
9991004
# string repr of a cycler-object, which gets eval()'ed
10001005
# to create the object.
1001-
'axes.prop_cycle': [ccycler('color', 'bgrcmyk'),
1002-
validate_cycler],
1006+
10031007
# If 'data', axes limits are set close to the data.
10041008
# If 'round_numbers' axes limits are set to the nearest round numbers.
10051009
'axes.autolimit_mode': [

matplotlibrc.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ backend : $TEMPLATE_BACKEND
9090
#lines.solid_capstyle : projecting # butt|round|projecting
9191
#lines.antialiased : True # render lines in antialiased (no jaggies)
9292

93+
# The three standard dash patterns. These are scaled by the linewidth.
94+
#lines.dashed_pattern : 2.8, 1.2
95+
#lines.dashdot_pattern : 4.8, 1.2, 0.8, 1.2
96+
#lines.dotted_pattern : 1.2, 0.6
97+
9398
#markers.fillstyle: full # full|left|right|bottom|top|none
9499

95100
### PATCHES

src/py_converters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ int convert_gcagg(PyObject *pygc, void *gcp)
476476
convert_from_attr(pygc, "_antialiased", &convert_bool, &gc->isaa) &&
477477
convert_from_attr(pygc, "_capstyle", &convert_cap, &gc->cap) &&
478478
convert_from_attr(pygc, "_joinstyle", &convert_join, &gc->join) &&
479-
convert_from_attr(pygc, "_dashes", &convert_dashes, &gc->dashes) &&
479+
convert_from_method(pygc, "get_dashes", &convert_dashes, &gc->dashes) &&
480480
convert_from_attr(pygc, "_cliprect", &convert_rect, &gc->cliprect) &&
481481
convert_from_method(pygc, "get_clip_path", &convert_clippath, &gc->clippath) &&
482482
convert_from_method(pygc, "get_snap", &convert_snap, &gc->snap_mode) &&

0 commit comments

Comments
 (0)