@@ -314,6 +314,18 @@ def __init__(self, xdata, ydata,
314314 if solid_joinstyle is None :
315315 solid_joinstyle = rcParams ['lines.solid_joinstyle' ]
316316
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+
317329 if drawstyle is None :
318330 drawstyle = 'default'
319331
@@ -979,6 +991,38 @@ def set_linewidth(self, w):
979991 self .stale = True
980992 self ._linewidth = w
981993
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+
9821026 def set_linestyle (self , ls ):
9831027 """
9841028 Set the linestyle of the line (also accepts drawstyles,
@@ -1030,15 +1074,9 @@ def set_linestyle(self, ls):
10301074 self .set_dashes (ls [1 ])
10311075 self ._linestyle = "--"
10321076 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 )
10421080
10431081 if ls in [' ' , '' , 'none' ]:
10441082 ls = 'None'
0 commit comments