본문 바로가기

프로그래밍/PyQt5 GUI

64. PyQtGraph 그래프 두 개 그리기

64-1 예제: ex63

import sys
import pyqtgraph as pg
from PyQt5.QtWidgets import QApplication, QMainWindow

class MyApp(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # 데이터
        x1 = [1, 2, 3, 4, 5]
        y1 = [10, 15, 20, 25, 30]
        x2 = [1, 2, 3, 4, 5]
        y2 = [1, 4, 9, 16, 23]

        plot_widget = pg.PlotWidget()
        self.setCentralWidget(plot_widget)

        # graph style
        plot_widget.setBackground('w')
        plot_widget.setTitle("이중 그래프")
        plot_widget.setLabel("left", "Y-축")
        plot_widget.setLabel("bottom", "X-축")
        plot_widget.addLegend()
        plot_widget.showGrid(x=True, y=True)

        # plot
        plot_widget.plot(x=x1, y=y1, pen=pg.mkPen(width=2, color='r'), name="plot1")
        plot_widget.plot(x=x2, y=y2, pen=pg.mkPen(width=2, color='g'), name="plot2")

        # window
        self.setGeometry(300, 300, 800, 600)
        self.setWindowTitle("이중 챠트 윈도우")
        self.show()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = MyApp()
    sys.exit(app.exec_())

64-2 결과

 

'프로그래밍 > PyQt5 GUI' 카테고리의 다른 글

67. PyQtChart 줄 그리기  (0) 2021.08.17
65. PyQtGraph 시계열 그래프 그리기  (0) 2021.08.13
63. PyQtGraph 기본 그래프 그리기  (0) 2021.08.12
62. 주가 챠트  (0) 2021.08.12
61. 주식 데이터  (0) 2021.08.12