44
55import os .path as osp
66
7+ import numpy as np
8+ from qtpy import QtCore as QC
79from qtpy import QtGui as QG
810from qtpy import QtWidgets as QW
911
@@ -20,15 +22,70 @@ def __init__(self):
2022 self .setTitle (self .TITLE )
2123 self .setAxisScale (self .yLeft , - 20 , 20 )
2224 self .setAxisScale (self .xBottom , - 20 , 20 )
25+ self .setup_plot ()
2326
24- curve = qwt .QwtPlotCurve ("Pixmap Points" )
25- curve .setSymbol (self .SYMBOL_CLASS ())
26- curve .setPen (QG .QPen (QG .QColor ("blue" )))
27- curve .setSamples ([- 15 , 0 , 15 , - 15 ], [0 , 15 , 0 , 0 ])
28- curve .attach (self )
29-
27+ def setup_plot (self ):
28+ samples = ([- 15 , 0 , 15 , - 15 ], [0 , 15 , 0 , 0 ])
29+ self .add_curve (self .TITLE , samples , self .SYMBOL_CLASS ())
3030 self .resize (400 , 400 )
3131
32+ def add_curve (self , title , samples , symbol = None ):
33+ """Add a curve to the plot"""
34+ curve = qwt .QwtPlotCurve (title )
35+ curve .setSamples (* samples )
36+ if symbol is not None :
37+ curve .setSymbol (symbol )
38+ curve .attach (self )
39+ self .replot ()
40+
41+
42+ class BuiltinSymbolPlot (BaseSymbolPlot ):
43+ TITLE = "Built-in Symbol Example"
44+
45+ def setup_plot (self ):
46+ colors = (QC .Qt .red , QC .Qt .green , QC .Qt .blue , QC .Qt .yellow , QC .Qt .magenta )
47+ for index , symbol_name in enumerate (
48+ (
49+ "Ellipse" ,
50+ "Rect" ,
51+ "Diamond" ,
52+ "Triangle" ,
53+ "DTriangle" ,
54+ "UTriangle" ,
55+ "LTriangle" ,
56+ "RTriangle" ,
57+ "Cross" ,
58+ "XCross" ,
59+ "HLine" ,
60+ "VLine" ,
61+ "Star1" ,
62+ "Star2" ,
63+ "Hexagon" ,
64+ )
65+ ):
66+ symbol = qwt .symbol .QwtSymbol (getattr (qwt .QwtSymbol , symbol_name ))
67+ symbol .setSize (7 , 7 )
68+ symbol .setPen (QG .QPen (colors [index % 3 ]))
69+ symbol .setBrush (QG .QBrush (QG .QColor (colors [index % 3 ]).lighter (150 )))
70+ x = np .linspace (- 10 , 10 , 100 )
71+ y = np .sin (x + index * np .pi / 10 )
72+ samples = (x , y )
73+ qwt .plot_marker .QwtPlotMarker .make (
74+ xvalue = index * 2 - 10 ,
75+ yvalue = index * 2 - 10 ,
76+ label = qwt .text .QwtText .make (
77+ "Marker" ,
78+ color = QC .Qt .black ,
79+ borderradius = 2 ,
80+ brush = QC .Qt .lightGray ,
81+ ),
82+ symbol = symbol ,
83+ plot = self ,
84+ )
85+ self .add_curve (symbol_name , samples , symbol )
86+ self .setAxisAutoScale (self .yLeft , True )
87+ self .setAxisAutoScale (self .xBottom , True )
88+
3289
3390class CustomGraphicSymbol (qwt .QwtSymbol ):
3491 def __init__ (self ):
@@ -110,6 +167,11 @@ def test_base():
110167 utils .test_widget (BaseSymbolPlot , size = (600 , 400 ))
111168
112169
170+ def test_builtin ():
171+ """Built-in symbol test"""
172+ utils .test_widget (BuiltinSymbolPlot , size = (600 , 400 ))
173+
174+
113175def test_graphic ():
114176 """Graphic symbol test"""
115177 utils .test_widget (GraphicPlot , size = (600 , 400 ))
@@ -132,6 +194,7 @@ def test_svg():
132194
133195if __name__ == "__main__" :
134196 test_base ()
197+ test_builtin ()
135198 test_graphic ()
136199 test_pixmap ()
137200 test_path ()
0 commit comments