欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PyQtGraph Basic Realization

程序员文章站 2024-01-20 17:08:46
Profile The Following Picture is the result of this time's work. It's the first step used to verify the basic function of PyQtGraph. Download PyQtGrap ......

profile

the following picture is the result of this time's work. it's the first step used to verify the basic function of pyqtgraph.

PyQtGraph Basic Realization

download pyqtgraph

it's always recommanded to download pyqtgraph through pip, as

 pip install pyqtgraph

if you want to speed up the download process, you can use the one provided by douban, use command as 

  pip install pyqtgraph -i https://pypi.douban.com/simple

inherit pyqtgraph.graphiclayoutwidget in qtdesigner

the basic conception of inheriting modules in qtdesigner would not be mentioned here. please google/baidu it by your self. 

following picture is the configuration.

PyQtGraph Basic Realization

after using pyuic to create the mainwindow class,  you would have found all this widget's setup is updated.

self.graphics_container = graphicslayoutwidget()
self.graphics_container.setgeometry(qtcore.qrect(0, 0, 1200, 450))
self.graphics_container.setminimumsize(qtcore.qsize(1200, 0))
self.graphics_container.setobjectname("graphics_container")

 the graphicslayoutwidget would be imported as well

from pyqtgraph import graphicslayoutwidget

add new graph in the widget

        plt1 = self.graphics_container.addplot(row=0,col=0)
        plt2 = self.graphics_container.addplot(row=1,col=0)
        plt3 = self.graphics_container.addplot(row=2,col=0)
        plt4 = self.graphics_container.addplot(row=3,col=0)
        plt5 = self.graphics_container.addplot(row=4,col=0)
        plt6 = self.graphics_container.addplot(row=5,col=0)        

create pattern of graph

        list1 = []
        for i in range(10):
            list1.extend(np.zeros(20))
            list1.extend(np.ones(20))        

call pattern in the graph

        plt1.plot(list1,pen=pg.mkpen(color='#aa0000', width=1),name="red line")
        plt2.plot(list1,pen=pg.mkpen(color='#aa0000', width=1),name="green line")
        plt3.plot(list1,pen=pg.mkpen(color='#aa0000', width=1),name="blue line")
        plt4.plot(list1,pen=pg.mkpen(color='#aa0000', width=1),name="green line")
        plt5.plot(list1,pen=pg.mkpen(color='#aa0000', width=1),name="green line")
        plt6.plot(list1,pen=pg.mkpen(color='#aa0000', width=1),name="green line")

pg is the pyqtgraph, which was imported as pg, through mkpen(**args) we can define the brush used in the graph, you can use the same way add more lines in the same plot

these is the first part of my work, to be continue