@@ -314,6 +314,18 @@ def __init__(self, xdata, ydata,
314
314
if solid_joinstyle is None :
315
315
solid_joinstyle = rcParams ['lines.solid_joinstyle' ]
316
316
317
+ if is_string_like (linestyle ):
318
+ ds , ls = self ._split_drawstyle_linestyle (linestyle )
319
+ if ds is not None and drawstyle is not None and ds != drawstyle :
320
+ raise ValueError ("Inconsistent drawstyle ({0!r}) and "
321
+ "linestyle ({1!r})" .format (drawstyle ,
322
+ linestyle )
323
+ )
324
+ linestyle = ls
325
+
326
+ if ds is not None :
327
+ drawstyle = ds
328
+
317
329
if drawstyle is None :
318
330
drawstyle = 'default'
319
331
@@ -332,8 +344,8 @@ def __init__(self, xdata, ydata,
332
344
333
345
self ._dashSeq = None
334
346
335
- self .set_drawstyle (drawstyle )
336
347
self .set_linestyle (linestyle )
348
+ self .set_drawstyle (drawstyle )
337
349
self .set_linewidth (linewidth )
338
350
339
351
self ._color = None
@@ -979,6 +991,38 @@ def set_linewidth(self, w):
979
991
self .stale = True
980
992
self ._linewidth = w
981
993
994
+ def _split_drawstyle_linestyle (self , ls ):
995
+ '''Split drawstyle from linestyle string
996
+
997
+ If `ls` is only a drawstyle default to returning a linestyle
998
+ of '-'.
999
+
1000
+ Parameters
1001
+ ----------
1002
+ ls : str
1003
+ The linestyle to be processed
1004
+
1005
+ Returns
1006
+ -------
1007
+ ret_ds : str or None
1008
+ If the linestyle string does not contain a drawstyle prefix
1009
+ return None, otherwise return it.
1010
+
1011
+ ls : str
1012
+ The linestyle with the drawstyle (if any) stripped.
1013
+ '''
1014
+ ret_ds = None
1015
+ for ds in self .drawStyleKeys : # long names are first in the list
1016
+ if ls .startswith (ds ):
1017
+ ret_ds = ds
1018
+ if len (ls ) > len (ds ):
1019
+ ls = ls [len (ds ):]
1020
+ else :
1021
+ ls = '-'
1022
+ break
1023
+
1024
+ return ret_ds , ls
1025
+
982
1026
def set_linestyle (self , ls ):
983
1027
"""
984
1028
Set the linestyle of the line (also accepts drawstyles,
@@ -1030,15 +1074,9 @@ def set_linestyle(self, ls):
1030
1074
self .set_dashes (ls [1 ])
1031
1075
self ._linestyle = "--"
1032
1076
return
1033
-
1034
- for ds in self .drawStyleKeys : # long names are first in the list
1035
- if ls .startswith (ds ):
1036
- self .set_drawstyle (ds )
1037
- if len (ls ) > len (ds ):
1038
- ls = ls [len (ds ):]
1039
- else :
1040
- ls = '-'
1041
- break
1077
+ ds , ls = self ._split_drawstyle_linestyle (ls )
1078
+ if ds is not None :
1079
+ self .set_drawstyle (ds )
1042
1080
1043
1081
if ls in [' ' , '' , 'none' ]:
1044
1082
ls = 'None'
0 commit comments