5858
5959class _ShapeItem (dict ):
6060 def __init__ (
61- self , x , y , shape , color , fill , overlay , linestyle , linewidth , gapcolor
61+ self , x , y , shape , color , fill , overlay , linewidth , dashpattern , gapcolor
6262 ):
6363 super (_ShapeItem , self ).__init__ ()
6464
@@ -84,8 +84,8 @@ def __init__(
8484 "fill" : "hatch" if fill else None ,
8585 "x" : x ,
8686 "y" : y ,
87- "linestyle" : linestyle ,
8887 "linewidth" : linewidth ,
88+ "dashpattern" : dashpattern ,
8989 "gapcolor" : gapcolor ,
9090 }
9191 )
@@ -99,8 +99,8 @@ def __init__(
9999 text ,
100100 color ,
101101 symbol ,
102- linestyle ,
103102 linewidth ,
103+ dashpattern ,
104104 constraint ,
105105 yaxis ,
106106 font ,
@@ -124,8 +124,8 @@ def __init__(
124124 "color" : colors .rgba (color ),
125125 "constraint" : constraint if isConstraint else None ,
126126 "symbol" : symbol ,
127- "linestyle" : linestyle ,
128127 "linewidth" : linewidth ,
128+ "dashpattern" : dashpattern ,
129129 "yaxis" : yaxis ,
130130 "font" : font ,
131131 "bgcolor" : bgcolor ,
@@ -575,7 +575,7 @@ def _renderItems(self, overlay=False):
575575 )
576576
577577 # Draw the stroke
578- if item ["linestyle " ] not in ( "" , " " , None ) :
578+ if item ["dashpattern " ] is not None :
579579 if item ["shape" ] != "polylines" :
580580 # close the polyline
581581 points = numpy .append (
@@ -585,10 +585,10 @@ def _renderItems(self, overlay=False):
585585 lines = glutils .GLLines2D (
586586 points [:, 0 ],
587587 points [:, 1 ],
588- style = item ["linestyle" ],
589588 color = item ["color" ],
590589 gapColor = item ["gapcolor" ],
591590 width = item ["linewidth" ],
591+ dashPattern = item ["dashpattern" ],
592592 )
593593 context .matrix = self .matScreenProj
594594 lines .render (context )
@@ -636,9 +636,9 @@ def _renderItems(self, overlay=False):
636636 lines = glutils .GLLines2D (
637637 (0 , width ),
638638 (pixelPos [1 ], pixelPos [1 ]),
639- style = item ["linestyle" ],
640639 color = color ,
641640 width = item ["linewidth" ],
641+ dashPattern = item ["dashpattern" ],
642642 )
643643 context .matrix = self .matScreenProj
644644 lines .render (context )
@@ -669,9 +669,9 @@ def _renderItems(self, overlay=False):
669669 lines = glutils .GLLines2D (
670670 (pixelPos [0 ], pixelPos [0 ]),
671671 (0 , height ),
672- style = item ["linestyle" ],
673672 color = color ,
674673 width = item ["linewidth" ],
674+ dashPattern = item ["dashpattern" ],
675675 )
676676 context .matrix = self .matScreenProj
677677 lines .render (context )
@@ -859,6 +859,22 @@ def _castArrayTo(v):
859859 else :
860860 raise ValueError ("Unsupported data type" )
861861
862+ _DASH_PATTERNS = { # Convert from linestyle to dash pattern
863+ "" : None ,
864+ " " : None ,
865+ "-" : (),
866+ "--" : (3.7 , 1.6 , 3.7 , 1.6 ),
867+ "-." : (6.4 , 1.6 , 1 , 1.6 ),
868+ ":" : (1 , 1.65 , 1 , 1.65 ),
869+ None : None ,
870+ }
871+
872+ def _lineStyleToDashPattern (
873+ self , style : str | None
874+ ) -> tuple [float , float , float , float ] | tuple [()] | None :
875+ """Convert a linestyle to its corresponding dash pattern"""
876+ return self ._DASH_PATTERNS [style ]
877+
862878 def addCurve (
863879 self ,
864880 x ,
@@ -977,16 +993,17 @@ def addCurve(
977993 fillColor = None
978994 if fill is True :
979995 fillColor = color
996+
980997 curve = glutils .GLPlotCurve2D (
981998 x ,
982999 y ,
9831000 colorArray ,
9841001 xError = xerror ,
9851002 yError = yerror ,
986- lineStyle = linestyle ,
9871003 lineColor = color ,
9881004 lineGapColor = gapcolor ,
9891005 lineWidth = linewidth ,
1006+ lineDashPattern = self ._lineStyleToDashPattern (linestyle ),
9901007 marker = symbol ,
9911008 markerColor = color ,
9921009 markerSize = symbolsize ,
@@ -1091,8 +1108,9 @@ def addShape(
10911108 if self ._plotFrame .yAxis .isLog and y .min () <= 0.0 :
10921109 raise RuntimeError ("Cannot add item with Y <= 0 with Y axis log scale" )
10931110
1111+ dashpattern = self ._lineStyleToDashPattern (linestyle )
10941112 return _ShapeItem (
1095- x , y , shape , color , fill , overlay , linestyle , linewidth , gapcolor
1113+ x , y , shape , color , fill , overlay , linewidth , dashpattern , gapcolor
10961114 )
10971115
10981116 def addMarker (
@@ -1110,14 +1128,15 @@ def addMarker(
11101128 bgcolor : RGBAColorType | None ,
11111129 ):
11121130 font = qt .QApplication .instance ().font () if font is None else font
1131+ dashpattern = self ._lineStyleToDashPattern (linestyle )
11131132 return _MarkerItem (
11141133 x ,
11151134 y ,
11161135 text ,
11171136 color ,
11181137 symbol ,
1119- linestyle ,
11201138 linewidth ,
1139+ dashpattern ,
11211140 constraint ,
11221141 yaxis ,
11231142 font ,
@@ -1209,7 +1228,7 @@ def __pickCurves(self, item, x, y):
12091228 qtDpi = self .getDotsPerInch () / self .getDevicePixelRatio ()
12101229 size = item .markerSize / 72.0 * qtDpi
12111230 offset = max (size / 2.0 , offset )
1212- if item .lineStyle is not None :
1231+ if item .lineDashPattern is not None :
12131232 # Convert line width from points to qt pixels
12141233 qtDpi = self .getDotsPerInch () / self .getDevicePixelRatio ()
12151234 lineWidth = item .lineWidth / 72.0 * qtDpi
0 commit comments