-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path3_Scatter_Style_Demo.py
97 lines (83 loc) · 3.51 KB
/
3_Scatter_Style_Demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import sys, math
from PyQt5.QtWidgets import QApplication, QGridLayout, QWidget
from PyQt5.QtGui import QPen, QColor, QFont, QPainterPath
from PyQt5.QtCore import Qt
from QCustomPlot_PyQt5 import QCustomPlot, QCPGraph, QCPScatterStyle
class MainForm(QWidget):
def __init__(self) -> None:
super().__init__()
self.setWindowTitle("Scatter Style Demo")
self.resize(400,400)
self.customPlot = QCustomPlot(self)
self.gridLayout = QGridLayout(self).addWidget(self.customPlot)
self.customPlot.legend.setVisible(True)
self.customPlot.legend.setFont(QFont("Helvetica", 9))
self.customPlot.legend.setRowSpacing(-3)
shapes = [
QCPScatterStyle.ssCross,
QCPScatterStyle.ssPlus,
QCPScatterStyle.ssCircle,
QCPScatterStyle.ssDisc,
QCPScatterStyle.ssSquare,
QCPScatterStyle.ssDiamond,
QCPScatterStyle.ssStar,
QCPScatterStyle.ssTriangle,
QCPScatterStyle.ssTriangleInverted,
QCPScatterStyle.ssCrossSquare,
QCPScatterStyle.ssPlusSquare,
QCPScatterStyle.ssCrossCircle,
QCPScatterStyle.ssPlusCircle,
QCPScatterStyle.ssPeace,
QCPScatterStyle.ssCustom
]
shapes_names = [
"ssCross",
"ssPlus",
"ssCircle",
"ssDisc",
"ssSquare",
"ssDiamond",
"ssStar",
"ssTriangle",
"ssTriangleInverted",
"ssCrossSquare",
"ssPlusSquare",
"ssCrossCircle",
"ssPlusCircle",
"ssPeace",
"ssCustom"
]
self.pen = QPen()
# add graphs with different scatter styles:
for i in range(len(shapes)):
self.customPlot.addGraph()
self.pen.setColor(QColor(int(math.sin(i*0.3)*100+100), int(math.sin(i*0.6+0.7)*100+100), int(math.sin(i*0.4+0.6)*100+100)))
# generate data:
x = [k/10.0 * 4*3.14 + 0.01 for k in range(10)]
y = [7*math.sin(x[k])/x[k] + (len(shapes)-i)*5 for k in range(10)]
self.customPlot.graph(i).setData(x, y)
self.customPlot.graph(i).rescaleAxes(True)
self.customPlot.graph(i).setPen(self.pen)
self.customPlot.graph(i).setName(shapes_names[i])
self.customPlot.graph(i).setLineStyle(QCPGraph.lsLine)
# set scatter style:
if shapes[i] != QCPScatterStyle.ssCustom:
self.customPlot.graph(i).setScatterStyle(QCPScatterStyle(shapes[i], 10))
else:
customScatterPath = QPainterPath()
for j in range(3):
customScatterPath.cubicTo(math.cos(2*math.pi*j/3.0)*9, math.sin(2*math.pi*j/3.0)*9, math.cos(2*math.pi*(j+0.9)/3.0)*9, math.sin(2*math.pi*(j+0.9)/3.0)*9, 0, 0)
self.customPlot.graph(i).setScatterStyle(QCPScatterStyle(customScatterPath, QPen(Qt.black, 0), QColor(40, 70, 255, 50), 10))
# set blank axis lines:
self.customPlot.rescaleAxes()
self.customPlot.xAxis.setTicks(False)
self.customPlot.yAxis.setTicks(False)
self.customPlot.xAxis.setTickLabels(False)
self.customPlot.yAxis.setTickLabels(False)
# make top right axes clones of bottom left axes:
self.customPlot.axisRect().setupFullAxesBox()
if __name__ == '__main__':
app = QApplication(sys.argv)
mainForm = MainForm()
mainForm.show()
sys.exit(app.exec())