pyqtgraph -- line chart 예제 2
개발환경 : windows 10 64bit, python 3.6.6 32bit, pyqt5, pyqtgraph 0.10.0 --> Anaconda 4.4.0 (32-bit) 사용
참고 : https://pythonprogramminglanguage.com/pyqtgraph-plot/
** addLegend(size=None, offset=(30, 30))
; 참고 -- http://pyqtgraph.org/documentation/graphicsItems/plotitem.html#pyqtgraph.PlotItem.addLegend
---> LegendItem() 없으면, 생성후 반환.
--> 매개변수는 LegendItem() 에서 사용
ex) LegendItem(size, offset) ==> size=(width,height)
---> 매개변수 size=None 인 경우, 내부적으로 자동 조절함. --> 이 경우 legend 에서 마크와 text 가 붙어서 안좋음.
; size 를 지정하여, default size 보다크게 지정하면 문제 해결됨.
-- size 를 작게 지정해도, 내부적으로 자동크기 조절함.
** setLabel(self, axis, text=None, units=None, unitPrefix=None, **args)
; 참고 -- http://pyqtgraph.org/documentation/graphicsItems/plotitem.html#pyqtgraph.PlotItem.setLabel
--> axis ; one of 'left', 'bottom', 'right', or 'top'
text ; axis 에 표시할 text
units ; units to display after the title. (자동으로 단위바뀜, ex; V --> mV or kV)
** setXRange(min, max, padding=None, update=True)
; 참고 -- http://pyqtgraph.org/documentation/graphicsItems/viewbox.html#pyqtgraph.ViewBox.setXRange
--- 내부적으로 ViewBox( ) 의 메소드 사용함.
--> x축 가시영역 최대, 최소 설정.
<< 실행화면 >>
<< 소스코드 >>
--
import pyqtgraph as pg | |
from PyQt5.QtWidgets import * | |
class MyWidget(QWidget): | |
def __init__(self): | |
super().__init__() | |
pg.setConfigOptions(background='w') # 배경 흰색으로.. ; global configuration options | |
y = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] | |
y2 = [0, 1, 2, 4, 12, 14, 16, 17, 14, 22] | |
x = range(0, 10) | |
pw = pg.PlotWidget() | |
pw.showGrid(x=True, y=True) | |
# pw.addLegend() # legend 글씨와 마크가 붙어서 출력됨 -- 시인성 나쁨 | |
pw.addLegend(size=(100, 10)) # LegendItem() 없으면, 생성후 반환 ; 매개변수는 LegendItem() 에서 사용 ==> size=(width,height) | |
pw.setLabel("left", text="Value", units="v") # PlotItem() 메소드 | |
pw.setLabel('bottom', text="Time", units='s') | |
pw.setXRange(0, 10) # 내부적으로 ViewBox() 메소드 사용함. -- setXRange(min, max, padding=None, update=True) | |
pw.setYRange(0, 25) | |
pw.plot(x, y, pen='b', symbol='x', symbolPen='g', symbolBrush=0.2, name='green') | |
pw.plot(x, y2, pen='r', symbol='o', symbolPen='b', symbolBrush=0.2, name='blue') | |
layout = QHBoxLayout() | |
layout.addWidget(pw) | |
self.setLayout(layout) | |
self.setGeometry(300, 100, 550, 650) # x, y, width, height | |
self.setWindowTitle("pyqtgraph 예제 2") | |
self.show() | |
if __name__ == '__main__': | |
import sys | |
app = QApplication(sys.argv) | |
ex = MyWidget() | |
sys.exit(app.exec_()) |
'PyQt5' 카테고리의 다른 글
pyqtgraph -- realtime chart 그리기 (0) | 2018.11.23 |
---|---|
pyqtgraph -- bar chart 그리기, 여백 제거 (0) | 2018.11.05 |
pyqtgraph -- pyqt5 에서 사용 -- line chart (1) | 2018.11.05 |
pyqt5 -- QObject 사용하는 singleton 만들기 (0) | 2018.10.26 |
PyQt5 -- QCalendarWidget,QDateEdit, QDateTimeEdit, QTimeEdit 사용하기 (0) | 2017.09.17 |