본문 바로가기

프로그래밍/PyQt5 GUI

65. PyQtGraph 시계열 그래프 그리기

시계열 데이터를 그래프로 그릴 때 시간축을 표현하는 것이 중요하고 어렵습니다.

pyqtgraph 0.12 버전부터 시간축을 표현하기 위한 DateAxisItem 클래스를 기본으로 제공하고 있습니다.

65-1 예제: ex64

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

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

    def initUI(self):
        # data 셀트리온
        df = fdr.DataReader("068270")     # pandas DataFrame 형식

        # widget
        gw = pg.PlotWidget(axisItems={'bottom': pg.DateAxisItem()})
        self.setCentralWidget(gw)

        # graph Style
        gw.setBackground('w')
        gw.setTitle("셀트리온 주가 챠트")
        gw.setLabel("left", "가격(원)")
        gw.setLabel("bottom", "날짜")
        gw.addLegend()
        gw.showGrid(x=True, y=True)

        # plot
        x = [t.timestamp() for t in df.index]
        gw.plot(x=x, y=df.Close)

        # window
        self.setGeometry(300, 300, 1200, 800)
        self.setWindowTitle("셀트리온 주가 그래프")
        self.show()

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

65-2 결과

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

68. PyQtChart 시계열 그래프  (0) 2021.08.17
67. PyQtChart 줄 그리기  (0) 2021.08.17
64. PyQtGraph 그래프 두 개 그리기  (0) 2021.08.13
63. PyQtGraph 기본 그래프 그리기  (0) 2021.08.12
62. 주가 챠트  (0) 2021.08.12