Data Visualization for the Development of Python3.x+pyqtgraph Real Crown Sports website
1, pyqtgraph database data Crown Sports website development haozbbs.com Q1446595067 visualization effect is good, especially the form program image interaction is good; installation is also very convenient, with pip installation.
2. Create a new .py file in Python, then write the following code and execute many cases (including codes) that can be provided officially, and the following interface image appears:
Import pyqtgraph.examplespyqtgraph.examples.run ()
Figure 1
Figure 2
Figure 3
4. The program defaults to a black background, which can be modified. For example, you can modify the background by writing the following code at the beginning of the program:
Pg.setConfigOption ('background', 'w') pg.setConfigOption (' foreground', 'k')
For more information, see the "Default Background and Foreground Colors" section of the pyqtgraph website: http://www.pyqtgraph.org/documentation/style.html, "Line, Fill, and Color" section.
5. A complete case of modifying the background color is as follows, you can run the program directly:
Import numpy as npimport pyqtgraph as pgfrom pyqtgraph.Qt import QtGui, QtCore# the following two lines of code are added by myself. The purpose is to change the default black background to another color background pg.setConfigOption ('background', 'w') pg.setConfigOption (' foreground', 'k') from pyqtgraph.Point import Point#generate layoutapp = QtGui.QApplication ([]) win = pg.GraphicsWindow () win.setWindowTitle ('pyqtgraph example: crosshair') label = pg.LabelItem (justify='right') win.addItem (label) p1 = win.addPlot (row=1, col=0) p2 = win.addPlot (row=2) Col=0) region = pg.LinearRegionItem () region.setZValue # Add the LinearRegionItem to the ViewBox, but tell the ViewBox to exclude this# item when doing auto-range calculations.p2.addItem (region, ignoreBounds=True) # pg.dbg () p1.setAutoVisible (y=True) # create numpy arrays#make the numbers large to show that the xrange shows data from 10000 to all the way 0data1 = 10000 + 15000 * pg.gaussianFilter (np.random.random (size=10000), 10) + 3000 * np.random.random (size=10000) data2 = 15000 + 15000 * pg.gaussianFilter (np.random.random (size=10000)) 10) + 3000 * np.random.random (size=10000) p1.plot (data1, pen= "r") p1.plot (data2, pen= "g") p2.plot (data1, pen= "w") def update (): region.setZValue (10) minX, maxX = region.getRegion () p1.setXRange (minX, maxX, padding=0) region.sigRegionChanged.connect (update) def updateRegion (window, viewRange): rgn = viewRange [0] region.setRegion (rgn) p1.sigRangeChanged.connect (updateRegion) region.setRegion 2000]) # cross hairvLine = pg.InfiniteLine (angle=90, movable=False) hLine = pg.InfiniteLine (angle=0, movable=False) p1.addItem (vLine, ignoreBounds=True) p1.addItem (hLine IgnoreBounds=True) vb = p1.vbdef mouseMoved (evt): pos = evt [0] # # using signal proxy turns original arguments into a tuple if p1.sceneBoundingRect (). Contains (pos): mousePoint = vb.mapSceneToView (pos) index = int (mousePoint.x () if index > 0 and index < len (data1): label.setText ("x% 0.1f, y1f% 0.1f, y2boat% 0.1f"% (mousePoint.x ()) Data1 [index], data2 [index]) vLine.setPos (mousePoint.x ()) hLine.setPos (mousePoint.y ()) proxy = pg.SignalProxy (p1.scene (). SigMouseMoved, rateLimit=60, slot=mouseMoved) # p1.scene (). SigMouseMoved.connect (mouseMoved) # # Start Qt event loop unless running in interactive mode or using pyside.if _ name__ = ='_ main__': import sys if (sys.flags.interactive! = 1) or not hasattr (QtCore) 'PYQT_VERSION'): QtGui.QApplication.instance (). Exec_ ()