[Python 수학] 그래프 라이브러리 PyQtGraph 2D Graph 예제 코드

 

 

# -*- coding: utf-8 -*-
"""
This example demonstrates many of the 2D plotting capabilities
in pyqtgraph. All of the plots may be panned/scaled by dragging with
the left/right mouse buttons. Right click on any plot to show a context menu.
"""
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg



#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])

#mw = QtGui.QMainWindow()
#mw.resize(800,800)



win = pg.GraphicsWindow(title="Basic plotting examples") # PyQtGraph grahical window
win.resize(1000,600)
win.setWindowTitle('pyqtgraph example: Plotting') # Title of python window



# Enable antialiasing for prettier plots
pg.setConfigOptions(antialias=True)


# Basic Array Plotting
p1 = win.addPlot(title="Basic array plotting", y=np.random.normal(size=100))


# Multiple Curves
p2 = win.addPlot(title="Multiple curves")
p2.plot(np.random.normal(size=100), pen=(255,0,0), name="Red curve")
p2.plot(np.random.normal(size=110)+5, pen=(0,255,0), name="Green curve")
p2.plot(np.random.normal(size=120)+10, pen=(0,0,255), name="Blue curve")


# Drawing with Points
p3 = win.addPlot(title="Drawing with points")
p3.plot(np.random.normal(size=100), pen=(200,200,200), symbolBrush=(255,0,0), symbolPen='w')


# Next Row
win.nextRow()


# Parametric, Grid Enabled
p4 = win.addPlot(title="Parametric, grid enabled")
x = np.cos(np.linspace(0, 2*np.pi, 1000))
y = np.sin(np.linspace(0, 4*np.pi, 1000))
p4.plot(x, y)
p4.showGrid(x=True, y=True)


# Scatter Plot, Axis Labels, Log Scale
p5 = win.addPlot(title="Scatter plot, axis labels, log scale")
x = np.random.normal(size=1000) * 1e-5
y = x*1000 + 0.005 * np.random.normal(size=1000)
y -= y.min()-1.0
mask = x > 1e-15
x = x[mask]
y = y[mask]
p5.plot(x, y, pen=None, symbol='t', symbolPen=None, symbolSize=10, symbolBrush=(100, 100, 255, 50))
p5.setLabel('left', "Y Axis", units='A')
p5.setLabel('bottom', "Y Axis", units='s')
p5.setLogMode(x=True, y=False)


# Updating Plot
p6 = win.addPlot(title="Updating plot")
curve = p6.plot(pen='y')
data = np.random.normal(size=(10,1000))
ptr = 0
def update():
global curve, data, ptr, p6
curve.setData(data[ptr%10])
if ptr == 0:
p6.enableAutoRange('xy', False) ## stop auto-scaling after the first data set is plotted
ptr += 1
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(50)


# Next Row
win.nextRow()


# Filled Plot, Axis Disabled
p7 = win.addPlot(title="Filled plot, axis disabled")
y = np.sin(np.linspace(0, 10, 1000)) + np.random.normal(size=1000, scale=0.1)
p7.plot(y, fillLevel=-0.3, brush=(50,50,200,100))
p7.showAxis('bottom', False)


# Region Selection
x2 = np.linspace(-100, 100, 1000)
data2 = np.sin(x2) / x2
p8 = win.addPlot(title="Region Selection")
p8.plot(data2, pen=(255,255,255,200))
lr = pg.LinearRegionItem([400,700])
lr.setZValue(-10)
p8.addItem(lr)


# Zoom on Selected Region
p9 = win.addPlot(title="Zoom on selected region")
p9.plot(data2)
def updatePlot():
p9.setXRange(*lr.getRegion(), padding=0)
def updateRegion():
lr.setRegion(p9.getViewBox().viewRange()[0])
lr.sigRegionChanged.connect(updatePlot)
p9.sigXRangeChanged.connect(updateRegion)
updatePlot()


## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

일반적으로 Python 환경에서 matplotlib를 가장 많이 사용하는데

 

실시간으로 업데이트 되는 그래프를 표시하기에 너무 느립니다.

 

찾아보니 PyQtGraph라는 라이브러리가 속도도 빠르고 수학적인 표현을 할 때

 

좋은 그래프가 많다고 하네요.

 

다만, 홈페이지의 문서가 상당히 불친절하게 되어 있어서 정보를 찾기가 쉽지 않습니다.

 

잘 사용만 한다면 쓸만한 그래픽 툴인 것 같습니다.

출처: https://mc10sw.tistory.com/10 [라이트터치:티스토리]

 

 

 

 

 

 

[Python 수학] 그래프 라이브러리 PyQtGraph 2D Graph 예제 코드

 

 

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

# -*- coding: utf-8 -*-
"""
This example demonstrates many of the 2D plotting capabilities
in pyqtgraph. All of the plots may be panned/scaled by dragging with
the left/right mouse buttons. Right click on any plot to show a context menu.
"""
from pyqtgraph.Qt import QtGuiQtCore
import numpy as np
import pyqtgraph as pg



#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])

#mw = QtGui.QMainWindow()
#mw.resize(800,800)



win = pg.GraphicsWindow(title="Basic plotting examples") # PyQtGraph grahical window
win.resize(1000,600)
win.setWindowTitle('pyqtgraph example: Plotting') # Title of python window



# Enable antialiasing for prettier plots
pg.setConfigOptions(antialias=True)


# Basic Array Plotting
p1 = win.addPlot(title="Basic array plotting"y=np.random.normal(size=100))


# Multiple Curves
p2 = win.addPlot(title="Multiple curves")
p2.plot(np.random.normal(size=100)pen=(255,0,0)name="Red curve")
p2.plot(np.random.normal(size=110)+5pen=(0,255,0)name="Green curve")
p2.plot(np.random.normal(size=120)+10pen=(0,0,255)name="Blue curve")


# Drawing with Points
p3 = win.addPlot(title="Drawing with points")
p3.plot(np.random.normal(size=100)pen=(200,200,200)symbolBrush=(255,0,0)symbolPen='w')


# Next Row
win.nextRow()


# Parametric, Grid Enabled
p4 = win.addPlot(title="Parametric, grid enabled")
x = np.cos(np.linspace(02*np.pi1000))
y = np.sin(np.linspace(04*np.pi1000))
p4.plot(xy)
p4.showGrid(x=True, y=True)


# Scatter Plot, Axis Labels, Log Scale
p5 = win.addPlot(title="Scatter plot, axis labels, log scale")
x = np.random.normal(size=1000) * 1e-5
y = x*1000 0.005 * np.random.normal(size=1000)
y -= y.min()-1.0
mask = x > 1e-15
x = x[mask]
y = y[mask]
p5.plot(xypen=None, symbol='t'symbolPen=None, symbolSize=10symbolBrush=(10010025550))
p5.setLabel('left'"Y Axis"units='A')
p5.setLabel('bottom'"Y Axis"units='s')
p5.setLogMode(x=True, y=False)


# Updating Plot
p6 = win.addPlot(title="Updating plot")
curve = p6.plot(pen='y')
data = np.random.normal(size=(10,1000))
ptr = 0
def update():
global curvedataptrp6
curve.setData(data[ptr%10])
if ptr == 0:
p6.enableAutoRange('xy', False) ## stop auto-scaling after the first data set is plotted
ptr += 1
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(50)


# Next Row
win.nextRow()


# Filled Plot, Axis Disabled
p7 = win.addPlot(title="Filled plot, axis disabled")
y = np.sin(np.linspace(0101000)) + np.random.normal(size=1000scale=0.1)
p7.plot(yfillLevel=-0.3brush=(50,50,200,100))
p7.showAxis('bottom', False)


# Region Selection
x2 = np.linspace(-1001001000)
data2 = np.sin(x2) / x2
p8 = win.addPlot(title="Region Selection")
p8.plot(data2pen=(255,255,255,200))
lr = pg.LinearRegionItem([400,700])
lr.setZValue(-10)
p8.addItem(lr)


# Zoom on Selected Region
p9 = win.addPlot(title="Zoom on selected region")
p9.plot(data2)
def updatePlot():
p9.setXRange(*lr.getRegion()padding=0)
def updateRegion():
lr.setRegion(p9.getViewBox().viewRange()[0])
lr.sigRegionChanged.connect(updatePlot)
p9.sigXRangeChanged.connect(updateRegion)
updatePlot()


## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1or not hasattr(QtCore'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

일반적으로 Python 환경에서 matplotlib를 가장 많이 사용하는데

 

실시간으로 업데이트 되는 그래프를 표시하기에 너무 느립니다.

 

찾아보니 PyQtGraph라는 라이브러리가 속도도 빠르고 수학적인 표현을 할 때

 

좋은 그래프가 많다고 하네요.

 

다만, 홈페이지의 문서가 상당히 불친절하게 되어 있어서 정보를 찾기가 쉽지 않습니다.

 

잘 사용만 한다면 쓸만한 그래픽 툴인 것 같습니다.

출처: https://mc10sw.tistory.com/10 [라이트터치:티스토리]

 

 

 

 

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
142 [Python 인터넷] PM2로 Python Flask 앱 관리하기 : Managing Python Flask App with PM2 file 졸리운_곰 2025.01.08 452
141 [Python 인터넷] Telegram bot! 봇 만들기 with 파이썬 file 졸리운_곰 2024.06.19 531
140 [Python 인터넷] python-screenshot-to-FTP /screengrab.py 졸리운_곰 2024.06.07 389
139 [Python 인터넷] IP 주소를 찾는 Python 프로그램 file 졸리운_곰 2024.06.07 365
138 [Python 인터넷] python 을 사용한 instagram (인스타그램) 자동 포스팅 : Automate Instagram Posts with Python: A Step-by-Step Guide 졸리운_곰 2024.05.19 317
137 [Python 인터넷] python 을 사용한 instagram (인스타그램) 자동 포스팅 : Automating Instagram Posts with Python: A Quick Guide file 졸리운_곰 2024.05.19 374
136 [Python 인터넷] 파이썬 셀레늄 네이버 포스트 자동 포스팅 방법 졸리운_곰 2024.05.05 442
135 [Python 인터넷] websocket을 이용한 python server에 대용량 파일 전송하기 졸리운_곰 2023.12.14 310
134 [Python 인터넷] [Python] Websocket을 사용하는 방법 file 졸리운_곰 2023.12.12 321
133 [Python 인터넷] 네이버 뉴스 기사 크롤링 졸리운_곰 2023.05.13 462
132 [Python 인터넷] 웹 페이지를 mhtml로 저장하기 python web page save as mthml 졸리운_곰 2023.04.12 448
131 [Python 인터넷] 16 - 셀레니움 이미지 크롤링, 스크롤 다운 file 졸리운_곰 2023.04.06 259
130 [Python 인터넷] 15 - 셀레니움 크롤링 (input) file 졸리운_곰 2023.04.06 406
129 [Python 인터넷] 14 - 셀레니움 click file 졸리운_곰 2023.04.06 538
128 [Python 인터넷] 13 - 셀레니움 사용해보기 file 졸리운_곰 2023.04.06 358
127 [Python 인터넷] 12 - 데이터 엑셀로 저장 file 졸리운_곰 2023.03.31 334
126 [Python 인터넷] 11 - Page 숫자 설정 file 졸리운_곰 2023.03.31 387
125 [Python 인터넷] 10 - 다음 뉴스 키워드로 크롤링 file 졸리운_곰 2023.03.30 363
124 [Python 인터넷] 9 - Flask POST file 졸리운_곰 2023.03.30 489
123 [Python 인터넷] 8 - 약간의 레이아웃 설정하기 file 졸리운_곰 2023.03.30 347
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED