6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PyQtGraphでグラフを描写する その3 - PlotWidgetの設定

Last updated at Posted at 2016-09-29

その3 PlotWidgetの設定

グラフの枠、軸の方向、背景色、サイズを設定する。

3.png

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 PlotWidgetを作成する
        ## 3 PlotWidgetの枠線、軸の方向を設定する
        pw = pg.PlotWidget(viewBox = pg.ViewBox(border = pg.mkPen(color='#000000'),
                                                invertX = False, invertY = True))

        # 1 ウィンドウにウィジェットを設定する
        self.setCentralWidget(pw)

        ## 3 背景色を設定する(#FFFFFF00: Transparent)
        pw.setBackground("#FFFFFF00")

        ## 3 グラフのサイズを固定する
        pw.setMinimumSize(500, 400)
        pw.setMaximumSize(500, 400)

        # 1 plotItemを呼び出す
        p1 = pw.plotItem

        # 1 散布図と折れ線グラフを描写する
        # 2 プロットの詳細を設定する
        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__':
    # Qt Applicationを作ります
    app = QApplication(sys.argv)
    # formを作成して表示します
    mainWin = GraphWindow()
    mainWin.show()
    # Qtのメインループを開始します
    sys.exit(app.exec_())
6
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?