Set the graph frame, axis direction, background color, and size.

import sys
from PySide.QtCore import *
from PySide.QtGui import *
import pyqtgraph as pg
class GraphWindow(QMainWindow):
    def __init__(self, parent = None):
        
        super(GraphWindow, self).__init__(parent)
        
        #1 Create a PlotWidget
        ##3 Set the border and axis direction of PlotWidget
        pw = pg.PlotWidget(viewBox = pg.ViewBox(border = pg.mkPen(color='#000000'),
                                                invertX = False, invertY = True))
        #1 Set the widget in the window
        self.setCentralWidget(pw)
        ##3 Set the background color(#FFFFFF00: Transparent)
        pw.setBackground("#FFFFFF00")
        ##3 Fix the size of the graph
        pw.setMinimumSize(500, 400)
        pw.setMaximumSize(500, 400)
        #1 Call plotItem
        p1 = pw.plotItem
        #1 Draw a scatter plot and a line graph
        #2 Set the plot details
        p1.addItem(pg.PlotCurveItem(x = [0, 1, 2, 3 ,4], 
                                    y = [0, 1, 2, 3 ,4], 
                                    pen = pg.mkPen(color = "r", style = Qt.SolidLine),
                                    antialias = True))
        p1.addItem(pg.ScatterPlotItem(x = [0, 1, 2, 3 ,4], 
                                      y = [4, 3, 2, 1, 0], 
                                      symbol = "x", 
                                      pen = pg.mkPen(None), 
                                      brush = pg.mkBrush("b"),
                                      size = 7.5,
                                      antialias = True))
if __name__ == '__main__':
    #Create a Qt Application
    app = QApplication(sys.argv)
    #Create and display form
    mainWin = GraphWindow()
    mainWin.show()
    #Start the main loop of Qt
    sys.exit(app.exec_())
        Recommended Posts