-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemoPrompt11.b_ChatGPT+Matplotlib.py
56 lines (45 loc) · 1.62 KB
/
demoPrompt11.b_ChatGPT+Matplotlib.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
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget, QPushButton
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import numpy as np
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Matplotlib with PyQt")
self.setGeometry(100, 100, 800, 600)
# Create a central widget
central_widget = QWidget()
self.setCentralWidget(central_widget)
# Create a layout for the central widget
layout = QVBoxLayout()
central_widget.setLayout(layout)
# Create a Matplotlib figure
self.figure = Figure(figsize=(5, 4), dpi=100)
self.canvas = FigureCanvas(self.figure)
layout.addWidget(self.canvas)
# Create a button to update the plot
button = QPushButton("Update Plot")
button.clicked.connect(self.update_plot)
layout.addWidget(button)
# Initial plot
self.update_plot()
def update_plot(self):
# Clear the previous plot
self.figure.clear()
# Generate data
x = np.linspace(0, 10, 100)
y = np.sin(x)
# Plot data
ax = self.figure.add_subplot(111)
ax.plot(x, y)
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_title('Matplotlib Plot')
# Update canvas
self.canvas.draw()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())