📜  PyQtGraph – 折线图

📅  最后修改于: 2022-05-13 01:54:36.356000             🧑  作者: Mango

PyQtGraph – 折线图

在本文中,我们将看到如何在 PyQtGraph 模块中创建折线图。 PyQtGraph 是一个用于Python的图形和用户界面库,它提供了设计和科学应用程序中通常需要的功能。它的主要目标是提供用于显示数据(绘图、视频等)的快速交互式图形,其次是提供有助于快速应用程序开发的工具(例如,Qt Designer 中使用的属性树)。
折线图或折线图或折线图或曲线图是一种将信息显示为由直线段连接的称为“标记”的一系列数据点的图表。它是许多领域中常见的一种基本类型的图表。线图是在 PyQtGraph 中的绘图类的帮助下创建的。

下面是实现

Python3
# importing pyqtgraph as pg
import pyqtgraph as pg
 
# importing QtCore and QtGui from the pyqtgraph module
from pyqtgraph.Qt import QtCore, QtGui
 
# importing numpy as np
import numpy as np
 
# define the data
title = "GeeksforGeeks PyQtGraph"
 
# y values to plot by line 1
y = [2, 8, 6, 8, 6, 11, 14, 13, 18, 19]
 
# y values to plot by line 2
y2 = [3, 1, 5, 8, 9, 11, 16, 17, 14, 16]
x = range(0, 10)
 
# create plot window object
plt = pg.plot()
 
# showing x and y grids
plt.showGrid(x = True, y = True)
 
# adding legend
plt.addLegend()
 
# set properties of the label for y axis
plt.setLabel('left', 'Vertical Values', units ='y')
 
# set properties of the label for x axis
plt.setLabel('bottom', 'Horizontal Values', units ='s')
 
# setting horizontal range
plt.setXRange(0, 10)
 
# setting vertical range
plt.setYRange(0, 20)
 
# setting window title to the plot window
plt.setWindowTitle(title)
 
# ploting line in green color
# with dot symbol as x, not a mandatory field
line1 = plt.plot(x, y, pen ='g', symbol ='x', symbolPen ='g',
                          symbolBrush = 0.2, name ='green')
 
# ploting line2 with blue color
# with dot symbol as o
line2 = plt.plot(x, y2, pen ='b', symbol ='o', symbolPen ='b',
                             symbolBrush = 0.2, name ='blue')
 
# main method
if __name__ == '__main__':
     
    # importing system
    import sys
     
    # Start Qt event loop unless running in interactive mode or using
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()


输出 :