pyqtgraph example
时间: 2023-09-29 17:05:44 浏览: 144
Sure! Here is a simple example of using PyQtGraph to create a basic plot:
```python
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
# Create the data
x = np.linspace(0, 10, 100)
y = np.sin(x)
# Create the application and main window
app = QtGui.QApplication([])
win = pg.GraphicsWindow(title="PyQtGraph Example")
win.resize(800, 600)
# Create a plot widget within the main window
plot = win.addPlot(title="Plotting Example")
plot.addLegend()
# Plot the data
plot.plot(x, y, pen='r', name='sin(x)')
# Customize the plot appearance
plot.setLabel('left', 'Amplitude', units='V')
plot.setLabel('bottom', 'Time', units='s')
# Enable grid
plot.showGrid(x=True, y=True)
# Start the Qt event loop
if __name__ == '__main__':
QtGui.QApplication.instance().exec_()
```
This example demonstrates how to create a PyQtGraph application, add a plot widget to the main window, plot some data, and customize the appearance of the plot. You can run this code to see a simple sine wave plot with grid lines.
阅读全文
相关推荐
















