# -*- coding: utf-8 -*- """ This example demonstrates many of the 2D plotting capabilities in pyqtgraph !ll of the plots may be panned"scaled by dragging #ith the left"right mouse buttons $ight clic% on any plot to sho# a context menu """ import init&xample ## !dd path to library '(ust for examples) you do not need this* from pyqtgraph+t import +t,ui- +t.ore import numpy as np import pyqtgraph as pg #+t,ui+!pplicationset,raphics/ystem'0raster0* app 1 +t,ui+!pplication'23* #m# 1 +t,ui+4ain5indo#'* #m#resi6e'877-877* #in 1 pg,raphics5indo#'title1"8asic plotting examples"* #inresi6e'9777-:77* #inset5indo#Title'0pyqtgraph example: ;lotting0* # &nable antialiasing for prettier plots pgset.onfig<ptions'antialias1True* p9 1 #inadd;lot'title1"8asic array plotting"- y1nprandomnormal'si6e1977** p2 1 #inadd;lot'title1"4ultiple cur=es"* p2plot'nprandomnormal'si6e1977*- pen1'2>>-7-7** p2plot'nprandomnormal'si6e1977*?>- pen1'7-2>>-7** p2plot'nprandomnormal'si6e1977*?97- pen1'7-7-2>>** p@ 1 #inadd;lot'title1"Dra#ing #ith points"* p@plot'nprandomnormal'si6e1977*- pen1'277-277-277*- symbol8rush1'2>>-7-7*- symbol;en10#0* #innext$o#'* pA 1 #inadd;lot'title1";arametric- grid enabled"* x 1 npcos'nplinspace'7- 2*nppi- 9777** y 1 npsin'nplinspace'7- A*nppi- 9777** pAplot'x- y* pAsho#,rid'x1True- y1True* p> 1 #inadd;lot'title1"/catter plot- axis labels- log scale"* x 1 nprandomnormal'si6e19777* * 9e-> y 1 x*9777 ? 777> * nprandomnormal'si6e19777* y -1 ymin'*-97 mas% 1 x B 9e-9> x 1 x2mas%3 y 1 y2mas%3 p>plot'x- y- pen1Cone- symbol10t0- symbol;en1Cone- symbol/i6e197- symbol8rush1'977- 977- 2>>- >7** p>setDabel'0left0- "E !xis"- units10!0* p>setDabel'0bottom0- "E !xis"- units10s0* p>setDog4ode'x1True- y1False* p: 1 #inadd;lot'title1"Gpdating plot"* cur=e 1 p:plot'pen10y0* data 1 nprandomnormal'si6e1'97-9777** ptr 1 7 def update'*: global cur=e- data- ptr- p: cur=esetData'data2ptrH973* if ptr 11 7: p:enable!uto$ange'0xy0- False* ## stop auto-scaling after the first data set is plotted ptr ?1 9 timer 1 +t.ore+Timer'* timertimeoutconnect'update* timerstart'>7* #innext$o#'* pI 1 #inadd;lot'title1"Filled plot- axis disabled"* y 1 npsin'nplinspace'7- 97- 9777** ? nprandomnormal'si6e19777- scale179* pIplot'y- fillDe=el1-7@- brush1'>7->7-277-977** pIsho#!xis'0bottom0- False* x2 1 nplinspace'-977- 977- 9777* data2 1 npsin'x2* " x2 p8 1 #inadd;lot'title1"$egion /election"* p8plot'data2- pen1'2>>-2>>-2>>-277** lr 1 pgDinear$egionJtem'2A77-I773* lrsetKLalue'-97* p8addJtem'lr* pM 1 #inadd;lot'title1"Koom on selected region"* pMplot'data2* def update;lot'*: pMsetN$ange'*lrget$egion'*- padding17* def update$egion'*: lrset$egion'pMgetLie#8ox'*=ie#$ange'*273* lrsig$egion.hangedconnect'update;lot* pMsigN$ange.hangedconnect'update$egion* update;lot'* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* !) "ratamiento #e imagenes # -*- coding: utf-8 -*- """ This example demonstrates the use of JmageLie#- #hich is a high-le=el #idget for displaying and analy6ing 2D and @D data JmageLie# pro=ides: 9 ! 6oomable region 'Lie#8ox* for displaying the image 2 ! combination histogram and gradient editor 'QistogramDGTJtem* for controlling the =isual appearance of the image @ ! timeline for selecting the currently displayed frame 'for @D data only* A Tools for =ery basic analysis of image data 'see $<J and Corm buttons* """ ## !dd path to library '(ust for examples) you do not need this* import init&xample import numpy as np import scipy from pyqtgraph+t import +t.ore- +t,ui import pyqtgraph as pg app 1 +t,ui+!pplication'23* ## .reate #indo# #ith JmageLie# #idget #in 1 +t,ui+4ain5indo#'* #inresi6e'877-877* im= 1 pgJmageLie#'* #inset.entral5idget'im=* #insho#'* #inset5indo#Title'0pyqtgraph example: JmageLie#0* ## .reate random @D data set #ith noisy signals img 1 scipyndimagegaussianOfilter'nprandomnormal'si6e1'277- 277**- '>- >** * 27 ? 977 img 1 img2npne#axis-:-:3 decay 1 npexp'-nplinspace'7-7@-977**2:-npne#axis-npne#axis3 data 1 nprandomnormal'si6e1'977- 277- 277** data ?1 img * decay data ?1 2 ## !dd time-=arying signal sig 1 np6eros'datashape273* sig2@7:3 ?1 npexp'-nplinspace'9-97- I7** sig2A7:3 ?1 npexp'-nplinspace'9-97- :7** sig2I7:3 ?1 npexp'-nplinspace'9-97- @7** sig 1 sig2:-npne#axis-npne#axis3 * @ data2:->7::7->7::73 ?1 sig ## Display the data and assign each frame a time =alue from 97 to @7 im=setJmage'data- x=als1nplinspace'9- @- datashape273** ## /tart +t e=ent loop unless running in interacti=e mode if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* $) Propie#a#es #el puntero """ Demonstrates some customi6ed mouse interaction by dra#ing a crosshair that follo#s the mouse """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import numpy as np import scipyndimage as ndi import pyqtgraph as pg from pyqtgraph+t import +t,ui- +t.ore from pyqtgraph;oint import ;oint #generate layout app 1 +t,ui+!pplication'23* #in 1 pg,raphics5indo#'* #inset5indo#Title'0pyqtgraph example: crosshair0* label 1 pgDabelJtem'(ustify10right0* #inaddJtem'label* p9 1 #inadd;lot'ro#19- col17* p2 1 #inadd;lot'ro#12- col17* region 1 pgDinear$egionJtem'* regionsetKLalue'97* # !dd the Dinear$egionJtem to the Lie#8ox- but tell the Lie#8ox to exclude this # item #hen doing auto-range calculations p2addJtem'region- ignore8ounds1True* #pgdbg'* p9set!utoLisible'y1True* #create numpy arrays #ma%e the numbers large to sho# that the xrange sho#s data from 97777 to all the #ay 7 data9 1 97777 ? 9>777 * ndigaussianOfilter'nprandomrandom'si6e197777*- 97* ? @777 * nprandomrandom'si6e197777* data2 1 9>777 ? 9>777 * ndigaussianOfilter'nprandomrandom'si6e197777*- 97* ? @777 * nprandomrandom'si6e197777* p9plot'data9- pen1"r"* p9plot'data2- pen1"g"* p2plot'data9- pen1"#"* def update'*: regionsetKLalue'97* minN- maxN 1 regionget$egion'* p9setN$ange'minN- maxN- padding17* regionsig$egion.hangedconnect'update* def update$egion'#indo#- =ie#$ange*: rgn 1 =ie#$ange273 regionset$egion'rgn* p9sig$ange.hangedconnect'update$egion* regionset$egion'29777- 27773* #cross hair =Dine 1 pgJnfiniteDine'angle1M7- mo=able1False* hDine 1 pgJnfiniteDine'angle17- mo=able1False* p9addJtem'=Dine- ignore8ounds1True* p9addJtem'hDine- ignore8ounds1True* =b 1 p9=b def mouse4o=ed'e=t*: pos 1 e=t273 ## using signal proxy turns original arguments into a tuple if p9scene8ounding$ect'*contains'pos*: mouse;oint 1 =bmap/ceneToLie#'pos* index 1 int'mouse;ointx'** if index B 7 and index R len'data9*: labelsetText'"Rspan style10font-si6e: 92pt0Bx1H79f- Rspan style10color: red0By91H79fR"spanB- Rspan style10color: green0By21H79fR"spanB" H 'mouse;ointx'*- data92index3- data22index3** =Dineset;os'mouse;ointx'** hDineset;os'mouse;ointy'** proxy 1 pg/ignal;roxy'p9scene'*sig4ouse4o=ed- rateDimit1:7- slot1mouse4o=ed* #p9scene'*sig4ouse4o=edconnect'mouse4o=ed* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* %) &ctuali'acion #e #atos mostra#os en pantalla # -*- coding: utf-8 -*- """ Demonstrate a simple data-slicing tas%: gi=en @D data 'displayed at top*- select a 2D plane and interpolate data along that plane to generate a slice image 'displayed at bottom* """ ## !dd path to library '(ust for examples) you do not need this* import init&xample import numpy as np import scipy from pyqtgraph+t import +t.ore- +t,ui import pyqtgraph as pg app 1 +t,ui+!pplication'23* ## .reate #indo# #ith t#o JmageLie# #idgets #in 1 +t,ui+4ain5indo#'* #inresi6e'877-877* #inset5indo#Title'0pyqtgraph example: Data/licing0* c# 1 +t,ui+5idget'* #inset.entral5idget'c#* l 1 +t,ui+,ridDayout'* c#setDayout'l* im=9 1 pgJmageLie#'* im=2 1 pgJmageLie#'* ladd5idget'im=9- 7- 7* ladd5idget'im=2- 9- 7* #insho#'* roi 1 pgDine/egment$<J'2297- :A3- 2927-:A33- pen10r0* im=9addJtem'roi* x9 1 nplinspace'-@7- 97- 928*2:- npne#axis- npne#axis3 x2 1 nplinspace'-27- 27- 928*2:- npne#axis- npne#axis3 y 1 nplinspace'-@7- 97- 928*2npne#axis- :- npne#axis3 6 1 nplinspace'-27- 27- 928*2npne#axis- npne#axis- :3 d9 1 npsqrt'x9**2 ? y**2 ? 6**2* d2 1 2*npsqrt'x92::-93**2 ? y**2 ? 6**2* d@ 1 A*npsqrt'x2**2 ? y2:-::-93**2 ? 6**2* data 1 'npsin'd9* " d9**2* ? 'npsin'd2* " d2**2* ? 'npsin'd@* " d@**2* def update'*: global data- im=9- im=2 d2 1 roiget!rray$egion'data- im=9imageJtem- axes1'9-2** im=2setJmage'd2*
roisig$egion.hangedconnect'update* ## Display the data im=9setJmage'data* im=9setQistogram$ange'-779- 779* im=9setDe=els'-777@- 777@* update'* ## /tart +t e=ent loop unless running in interacti=e mode if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* () Personali'ar graficos )comportamientos) # -*- coding: utf-8 -*- """ This example demonstrates the creation of a plot #ith a customi6ed !xisJtem and Lie#8ox """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import numpy as np import time class Date!xis'pg!xisJtem*: def tic%/trings'self- =alues- scale- spacing*: strns 1 23 rng 1 max'=alues*-min'=alues* #if rng R 927: # return pg!xisJtemtic%/trings'self- =alues- scale- spacing* if rng R @:77*2A: string 1 0HQ:H4:H/0 label9 1 0Hb Hd -0 label2 1 0 Hb Hd- HE0 elif rng B1 @:77*2A and rng R @:77*2A*@7: string 1 0Hd0 label9 1 0Hb - 0 label2 1 0Hb- HE0 elif rng B1 @:77*2A*@7 and rng R @:77*2A*@7*2A: string 1 0Hb0 label9 1 0HE -0 label2 1 0 HE0 elif rng B1@:77*2A*@7*2A: string 1 0HE0 label9 1 00 label2 1 00 for x in =alues: try: strnsappend'timestrftime'string- timelocaltime'x*** except Lalue&rror: ## 5indo#s can0t handle dates before 9MI7 strnsappend'00* try: label 1 timestrftime'label9- timelocaltime'min'=alues***?timestrftime'label2- timelocaltime'max'=alues*** except Lalue&rror: label 1 00 #selfsetDabel'text1label* return strns class .ustomLie#8ox'pgLie#8ox*: def OOinitOO'self- *args- **%#ds*: pgLie#8oxOOinitOO'self- *args- **%#ds* selfset4ouse4ode'self$ect4ode*
## reimplement right-clic% to 6oom out def mouse.lic%&=ent'self- e=*: if e=button'* 11 +t.ore+t$ight8utton: selfauto$ange'*
def mouseDrag&=ent'self- e=*: if e=button'* 11 +t.ore+t$ight8utton: e=ignore'* else: pgLie#8oxmouseDrag&=ent'self- e=* app 1 pgm%+!pp'* axis 1 Date!xis'orientation10bottom0* =b 1 .ustomLie#8ox'* p# 1 pg;lot5idget'=ie#8ox1=b- axisJtems1S0bottom0: axisT- enable4enu1False- title1";lotJtem #ith custom axis and Lie#8oxRbrB4enu disabled- mouse beha=ior changed: left-drag to 6oom- right-clic% to reset 6oom"* dates 1 nparange'8* * '@:77*2A*@>:* p#plot'x1dates- y129-:-2-A-@->-:-83- symbol10o0* p#sho#'* p#set5indo#Title'0pyqtgraph example: custom;lot0* r 1 pg;olyDine$<J'2'7-7*- '97- 97*3* p#addJtem'r* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* *) +i#gets empotra,les # -*- coding: utf-8 -*- """ This example demonstrates the use of pyqtgraph0s doc% #idget system The doc%area system allo#s the design of user interfaces #hich can be rearranged by the user at runtime Doc%s can be mo=ed- resi6ed- stac%ed- and torn out of the main #indo# This is similar in principle to the doc%ing system built into +t- but offers a more deterministic doc% placement !;J 'in +t it is =ery difficult to programatically generate complex doc% arrangements* !dditionally- +t0s doc%s are designed to be used as small panels around the outer edge of a #indo# ;yqtgraph0s doc%s #ere created #ith the notion that the entire #indo# 'or any portion of it* #ould consist of doc%able components """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import pyqtgraphconsole import numpy as np from pyqtgraphdoc%area import * app 1 +t,ui+!pplication'23* #in 1 +t,ui+4ain5indo#'* area 1 Doc%!rea'* #inset.entral5idget'area* #inresi6e'9777->77* #inset5indo#Title'0pyqtgraph example: doc%area0* ## .reate doc%s- place them into the #indo# one at a time ## Cote that si6e arguments are only a suggestion) doc%s #ill still ha=e to ## fill the entire doc% area and obey the limits of their internal #idgets d9 1 Doc%'"Doc%9"- si6e1'9- 9** ## gi=e this doc% the minimum possible si6e d2 1 Doc%'"Doc%2 - .onsole"- si6e1'>77-@77** d@ 1 Doc%'"Doc%@"- si6e1'>77-A77** dA 1 Doc%'"Doc%A 'tabbed* - ;lot"- si6e1'>77-277** d> 1 Doc%'"Doc%> - Jmage"- si6e1'>77-277** d: 1 Doc%'"Doc%: 'tabbed* - ;lot"- si6e1'>77-277** areaaddDoc%'d9- 0left0* ## place d9 at left edge of doc% area 'it #ill fill the #hole space since there are no other doc%s yet* areaaddDoc%'d2- 0right0* ## place d2 at right edge of doc% area areaaddDoc%'d@- 0bottom0- d9*## place d@ at bottom edge of d9 areaaddDoc%'dA- 0right0* ## place dA at right edge of doc% area areaaddDoc%'d>- 0left0- d9* ## place d> at left edge of d9 areaaddDoc%'d:- 0top0- dA* ## place d> at top edge of dA ## Test ability to mo=e doc%s programatically after they ha=e been placed areamo=eDoc%'dA- 0top0- d2* ## mo=e dA to top edge of d2 areamo=eDoc%'d:- 0abo=e0- dA* ## mo=e d: to stac% on top of dA areamo=eDoc%'d>- 0top0- d2* ## mo=e d> to top edge of d2 ## !dd #idgets into each doc% ## first doc% gets sa=e"restore buttons #9 1 pgDayout5idget'* label 1 +t,ui+Dabel'""" -- Doc%!rea &xample -- This #indo# has : Doc% #idgets in it &ach doc% can be dragged by its title bar to occupy a different space #ithin the #indo# but note that one doc% has its title bar hidden* !dditionally- the borders bet#een doc%s may be dragged to resi6e Doc%s that are dragged on top of one another are stac%ed in a tabbed layout Double-clic% a doc% title bar to place it in its o#n #indo# """* sa=e8tn 1 +t,ui+;ush8utton'0/a=e doc% state0* restore8tn 1 +t,ui+;ush8utton'0$estore doc% state0* restore8tnset&nabled'False* #9add5idget'label- ro#17- col17* #9add5idget'sa=e8tn- ro#19- col17* #9add5idget'restore8tn- ro#12- col17* d9add5idget'#9* state 1 Cone def sa=e'*: global state state 1 areasa=e/tate'* restore8tnset&nabled'True* def load'*: global state arearestore/tate'state* sa=e8tnclic%edconnect'sa=e* restore8tnclic%edconnect'load* #2 1 pgconsole.onsole5idget'* d2add5idget'#2* ## Qide title bar on doc% @ d@hideTitle8ar'* #@ 1 pg;lot5idget'title1";lot inside doc% #ith no title bar"* #@plot'nprandomnormal'si6e1977** d@add5idget'#@* #A 1 pg;lot5idget'title1"Doc% A plot"* #Aplot'nprandomnormal'si6e1977** dAadd5idget'#A* #> 1 pgJmageLie#'* #>setJmage'nprandomnormal'si6e1'977-977*** d>add5idget'#>* #: 1 pg;lot5idget'title1"Doc% : plot"* #:plot'nprandomnormal'si6e1977** d:add5idget'#:* #insho#'* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* -) .onsola # -*- coding: utf-8 -*- """ .onsole5idget is used to allo# execution of user-supplied python commands in an application Jt also includes a command history and functionality for trapping and inspecting stac% traces """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import numpy as np import pyqtgraphconsole app 1 pgm%+!pp'* ## build an initial namespace for console commands to be executed in 'this is optional) ## the user can al#ays import these modules manually* namespace 1 S0pg0: pg- 0np0: npT ## initial text to display in the console text 1 """ This is an interacti=e python console The numpy and pyqtgraph modules ha=e already been imported as 0np0 and 0pg0 ,o- play """ c 1 pyqtgraphconsole.onsole5idget'namespace1namespace- text1text* csho#'* cset5indo#Title'0pyqtgraph example: .onsole5idget0* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* /) 0istogramas # -*- coding: utf-8 -*- """ Jn this example #e dra# t#o different %inds of histogram """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import numpy as np #in 1 pg,raphics5indo#'* #inresi6e'877-@>7* #inset5indo#Title'0pyqtgraph example: Qistogram0* plt9 1 #inadd;lot'* plt2 1 #inadd;lot'* ## ma%e interesting distribution of =alues =als 1 nphstac%'2nprandomnormal'si6e1>77*- nprandomnormal'si6e12:7- loc1A*3* ## compute standard histogram y-x 1 nphistogram'=als- bins1nplinspace'-@- 8- A7** ## notice that len'x* 11 len'y*?9 ## 5e are required to use step4ode1True so that ;lot.ur=eJtem #ill interpret this data correctly cur=e 1 pg;lot.ur=eJtem'x- y- step4ode1True- fillDe=el17- brush1'7- 7- 2>>- 87** plt9addJtem'cur=e* ## Co# dra# all points as a nicely-spaced scatter plot y 1 pgpseudo/catter'=als- spacing179>* #plt2plot'=als- y- pen1Cone- symbol10o0- symbol/i6e1>* plt2plot'=als- y- pen1Cone- symbol10o0- symbol/i6e1>- symbol;en1'2>>-2>>-2>>-277*- symbol8rush1'7-7-2>>-9>7** ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* 1) &uto a2uste y actuali'acion # -*- coding: utf-8 -*- """ This example demonstrates the different auto-ranging capabilities of Lie#8oxes """ import init&xample ## !dd path to library '(ust for examples) you do not need this* from pyqtgraph+t import +t,ui- +t.ore import numpy as np import pyqtgraph as pg #+t,ui+!pplicationset,raphics/ystem'0raster0* app 1 +t,ui+!pplication'23* #m# 1 +t,ui+4ain5indo#'* #m#resi6e'877-877* #in 1 pg,raphics5indo#'title1";lot auto-range examples"* #inresi6e'877-:77* #inset5indo#Title'0pyqtgraph example: ;lot!uto$ange0* d 1 nprandomnormal'si6e1977* d2>7:>A3 ?1 97 p9 1 #inadd;lot'title1"M>th percentile range"- y1d* p9enable!uto$ange'0y0- 7M>* p2 1 #inadd;lot'title1"!uto ;an <nly"* p2set!uto;an'y1True* cur=e 1 p2plot'* def update'*: t 1 pgtime'*
data 1 npones'977* * npsin't* data2>7::73 ?1 npsin't* global cur=e cur=esetData'data*
timer 1 +t.ore+Timer'* timertimeoutconnect'update* timerstart'>7* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+!pplicationinstance'*execO'* 13) Grafican#o remotamente # -*- coding: utf-8 -*- """ This example demonstrates the use of $emote,raphicsLie# to impro=e performance in applications #ith hea=y load Jt #or%s by starting a second process to handle all graphics rendering- thus freeing up the main process to do its #or% Jn this example- the update'* function is =ery expensi=e and is called frequently !fter update'* generates a ne# set of data- it can either plot directly to a local plot 'bottom* or remotely =ia a $emote,raphicsLie# 'top*- allo#ing speed comparison bet#een the t#o cases JF you ha=e a multi-core .;G- it should be ob=ious that the remote case is much faster """ import init&xample ## !dd path to library '(ust for examples) you do not need this* from pyqtgraph+t import +t,ui- +t.ore import pyqtgraph as pg import pyqtgraph#idgets$emote,raphicsLie# import numpy as np app 1 pgm%+!pp'* =ie# 1 pg#idgets$emote,raphicsLie#$emote,raphicsLie#'* pgset.onfig<ptions'antialias1True* ## this #ill be expensi=e for the local plot =ie#pgset.onfig<ptions'antialias1True* ## prettier plots at no cost to the main processP =ie#set5indo#Title'0pyqtgraph example: $emote/peedTest0* label 1 +t,ui+Dabel'* rchec% 1 +t,ui+.hec%8ox'0plot remote0* rchec%set.hec%ed'True* lchec% 1 +t,ui+.hec%8ox'0plot local0* lplt 1 pg;lot5idget'* layout 1 pgDayout5idget'* layoutadd5idget'rchec%* layoutadd5idget'lchec%* layoutadd5idget'label* layoutadd5idget'=ie#- ro#19- col17- colspan1@* layoutadd5idget'lplt- ro#12- col17- colspan1@* layoutresi6e'877-877* layoutsho#'* ## .reate a ;lotJtem in the remote process that #ill be displayed locally rplt 1 =ie#pg;lotJtem'* rpltOset;roxy<ptions'defer,etattr1True* ## speeds up access to rpltplot =ie#set.entralJtem'rplt* lastGpdate 1 pgptimetime'* a=gFps 1 77 def update'*: global chec%- label- plt- lastGpdate- a=gFps- rpltfunc data 1 nprandomnormal'si6e1'97777->7**sum'axis19* data ?1 > * npsin'nplinspace'7- 97- datashape273**
if rchec%is.hec%ed'*: rpltplot'data- clear1True- Ocall/ync10off0* ## 5e do not expect a return =alue ## 8y turning off call/ync- #e tell ## the proxy that it does not need to ## #ait for a reply from the remote ## process if lchec%is.hec%ed'*: lpltplot'data- clear1True*
timer 1 +t.ore+Timer'* timertimeoutconnect'update* timerstart'7* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* 11) Graficos #e #ispersion # -*- coding: utf-8 -*- """ &xample demonstrating a =ariety of scatter plot features """ ## !dd path to library '(ust for examples) you do not need this* import init&xample from pyqtgraph+t import +t,ui- +t.ore import pyqtgraph as pg import numpy as np app 1 +t,ui+!pplication'23* m# 1 +t,ui+4ain5indo#'* m#resi6e'877-877* =ie# 1 pg,raphicsDayout5idget'* ## ,raphicsLie# #ith ,raphicsDayout inserted by default m#set.entral5idget'=ie#* m#sho#'* m#set5indo#Title'0pyqtgraph example: /catter;lot0* ## create four areas to add plots #9 1 =ie#add;lot'* #2 1 =ie#addLie#8ox'* #2set!spectDoc%ed'True* =ie#next$o#'* #@ 1 =ie#add;lot'* #A 1 =ie#add;lot'* print'",enerating data- this ta%es a fe# seconds"* ## There are a fe# different #ays #e can dra# scatter plots) each is optimi6ed for different types of data: ## 9* !ll spots identical and transform-in=ariant 'top-left plot* ## Jn this case #e can get a huge performance boost by pre-rendering the spot ## image and (ust dra#ing that image repeatedly n 1 @77 s9 1 pg/catter;lotJtem'si6e197- pen1pgm%;en'Cone*- brush1pgm%8rush'2>>- 2>>- 2>>- 927** pos 1 nprandomnormal'si6e1'2-n*- scale19e->* spots 1 2S0pos0: pos2:-i3- 0data0: 9T for i in range'n*3 ? 2S0pos0: 27-73- 0data0: 9T3 s9add;oints'spots* #9addJtem's9* ## 4a%e all plots clic%able last.lic%ed 1 23 def clic%ed'plot- points*: global last.lic%ed for p in last.lic%ed: preset;en'* print'"clic%ed points"- points* for p in points: pset;en'0b0- #idth12* last.lic%ed 1 points s9sig.lic%edconnect'clic%ed* ## 2* /pots are transform-in=ariant- but not identical 'top-right plot* ## Jn this case- dra#ing is as fast as 9*- but there is more startup o=erhead ## and memory usage since each spot generates its o#n pre-rendered image s2 1 pg/catter;lotJtem'si6e197- pen1pgm%;en'0#0*- px4ode1True* pos 1 nprandomnormal'si6e1'2-n*- scale19e->* spots 1 2S0pos0: pos2:-i3- 0data0: 9- 0brush0:pgint.olor'i- n*- 0symbol0: iH>- 0si6e0: >?i"97T for i in range'n*3 s2add;oints'spots* #2addJtem's2* s2sig.lic%edconnect'clic%ed* ## @* /pots are not transform-in=ariant- not identical 'bottom-left* ## This is the slo#est case- since all spots must be completely re-dra#n ## e=ery time because their apparent transformation may ha=e changed s@ 1 pg/catter;lotJtem'px4ode1False* ## /et px4ode1False to allo# spots to transform #ith the =ie# spots@ 1 23 for i in range'97*: for ( in range'97*: spots@append'S0pos0: '9e-:*i- 9e-:*(*- 0si6e0: 9e-:- 0pen0: S0color0: 0#0- 0#idth0: 2T- 0brush0:pgint.olor'i*97?(- 977*T* s@add;oints'spots@* #@addJtem's@* s@sig.lic%edconnect'clic%ed* ## Test performance of large scatterplots sA 1 pg/catter;lotJtem'si6e197- pen1pgm%;en'Cone*- brush1pgm%8rush'2>>- 2>>- 2>>- 27** pos 1 nprandomnormal'si6e1'2-97777*- scale19e-M* sAadd;oints'x1pos273- y1pos293* #AaddJtem'sA* sAsig.lic%edconnect'clic%ed* ## /tart +t e=ent loop unless running in interacti=e mode if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+!pplicationinstance'*execO'* 1!) Lineas 4iso5 # -*- coding: utf-8 -*- """ Tests use of Jso.ur=e item displayed #ith image """ import init&xample ## !dd path to library '(ust for examples) you do not need this* from pyqtgraph+t import +t,ui- +t.ore import numpy as np import pyqtgraph as pg import scipyndimage as ndi app 1 +t,ui+!pplication'23* ## ma%e pretty looping data frames 1 277 data 1 nprandomnormal'si6e1'frames-@7-@7*- loc17- scale1977* data 1 npconcatenate'2data- data3- axis17* data 1 ndigaussianOfilter'data- '97- 97- 97**2frames"2:frames ? frames"23 data2:- 9>:9:- 9>:9I3 ?1 9 #in 1 pg,raphics5indo#'* #inset5indo#Title'0pyqtgraph example: Jsocur=e0* =b 1 #inaddLie#8ox'* img 1 pgJmageJtem'data273* =baddJtem'img* =bset!spectDoc%ed'* ## generate empty cur=es cur=es 1 23 le=els 1 nplinspace'datamin'*- datamax'*- 97* for i in range'len'le=els**: = 1 le=els2i3 ## generate isocur=e #ith automatic color selection c 1 pgJsocur=eJtem'le=el1=- pen1'i- len'le=els**9>** cset;arentJtem'img* ## ma%e sure isocur=e is al#ays correctly displayed o=er image csetKLalue'97* cur=esappend'c* ## animateP ptr 1 7 imgDe=els 1 'datamin'*- datamax'* * 2* def update'*: global data- cur=es- img- ptr- imgDe=els ptr 1 'ptr ? 9* H datashape273 data2ptr3 imgsetJmage'data2ptr3- le=els1imgDe=els* for c in cur=es: csetData'data2ptr3* timer 1 +t.ore+Timer'* timertimeoutconnect'update* timerstart'>7*
## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* 1$) Graph item # -*- coding: utf-8 -*- """ /imple example of ,raphJtem use """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import numpy as np # &nable antialiasing for prettier plots pgset.onfig<ptions'antialias1True* # 1 pg,raphics5indo#'* #set5indo#Title'0pyqtgraph example: ,raphJtem0* = 1 #addLie#8ox'* =set!spectDoc%ed'* g 1 pg,raphJtem'* =addJtem'g* ## Define positions of nodes pos 1 nparray'2 27-73- 297-73- 27-973- 297-973- 2>->3- 29>->3 3*
## Define the set of connections in the graph ad( 1 nparray'2 27-93- 29-@3- 2@-23- 22-73- 29->3- 2@->3- 3*
## Define the symbol to use for each node 'this is optional* symbols 1 20o0-0o0-0o0-0o0-0t0-0?03 ## Define the line style for each connection 'this is optional* lines 1 nparray'2 '2>>-7-7-2>>-9*- '2>>-7-2>>-2>>-2*- '2>>-7-2>>-2>>-@*- '2>>-2>>-7-2>>-2*- '2>>-7-7-2>>-9*- '2>>-2>>-2>>-2>>-A*- 3- dtype12'0red0-npubyte*-'0green0-npubyte*-'0blue0-npubyte*- '0alpha0-npubyte*-'0#idth0-float*3* ## Gpdate the graph gsetData'pos1pos- ad(1ad(- pen1lines- si6e19- symbol1symbols- px4ode1False* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* 1%) Error6ar7tem # -*- coding: utf-8 -*- """ Demonstrates basic use of &rror8arJtem """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t,ui import numpy as np import pyqtgraph as pg import numpy as np pgset.onfig<ptions'antialias1True* x 1 nparange'97* y 1 nparange'97* H@ top 1 nplinspace'97- @7- 97* bottom 1 nplinspace'2- 7>- 97* plt 1 pgplot'* pltset5indo#Title'0pyqtgraph example: &rror8arJtem0* err 1 pg&rror8arJtem'x1x- y1y- top1top- bottom1bottom- beam17>* pltaddJtem'err* pltplot'x- y- symbol10o0- pen1S0color0: 78- 0#idth0: 2T* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* 1() 7mage7tem 8 vi#eo # -*- coding: utf-8 -*- """ Demonstrates =ery basic use of JmageJtem to display image data inside a Lie#8ox """ ## !dd path to library '(ust for examples) you do not need this* import init&xample from pyqtgraph+t import +t.ore- +t,ui import numpy as np import pyqtgraph as pg import pyqtgraphptime as ptime app 1 +t,ui+!pplication'23* ## .reate #indo# #ith ,raphicsLie# #idget #in 1 pg,raphicsDayout5idget'* #insho#'* ## sho# #idget alone in its o#n #indo# #inset5indo#Title'0pyqtgraph example: JmageJtem0* =ie# 1 #inaddLie#8ox'* ## loc% the aspect ratio so pixels are al#ays square =ie#set!spectDoc%ed'True* ## .reate image item img 1 pgJmageJtem'border10#0* =ie#addJtem'img* ## /et initial =ie# bounds =ie#set$ange'+t.ore+$ectF'7- 7- :77- :77** ## .reate random image data 1 nprandomnormal'si6e1'9>- :77- :77*- loc1972A- scale1:A*astype'npuint9:* i 1 7 updateTime 1 ptimetime'* fps 1 7 def updateData'*: global img- data- i- updateTime- fps ## Display the data imgsetJmage'data2i3* i 1 'i?9* H datashape273 +t.ore+Timersingle/hot'9- updateData* no# 1 ptimetime'* fps2 1 97 " 'no#-updateTime* updateTime 1 no# fps 1 fps * 7M ? fps2 * 79
#print "H79f fps" H fps
updateData'* ## /tart +t e=ent loop unless running in interacti=e mode if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* 1*) 7mage7tem 9 #ra: )la imagen la pinte con el puntero) # -*- coding: utf-8 -*- """ Demonstrate ability of JmageJtem to be used as a can=as for painting #ith the mouse """ import init&xample ## !dd path to library '(ust for examples) you do not need this* from pyqtgraph+t import +t.ore- +t,ui import numpy as np import pyqtgraph as pg app 1 +t,ui+!pplication'23* ## .reate #indo# #ith ,raphicsLie# #idget # 1 pg,raphicsLie#'* #sho#'* #resi6e'877-877* #set5indo#Title'0pyqtgraph example: Dra#0* =ie# 1 pgLie#8ox'* #set.entralJtem'=ie#* ## loc% the aspect ratio =ie#set!spectDoc%ed'True* ## .reate image item img 1 pgJmageJtem'np6eros''277-277*** =ie#addJtem'img* ## /et initial =ie# bounds =ie#set$ange'+t.ore+$ectF'7- 7- 277- 277** ## start dra#ing #ith @x@ brush %ern 1 nparray'2 277- 7>- 773- 27>- 97- 7>3- 277- 7>- 773 3* imgsetDra#Uernel'%ern- mas%1%ern- center1'9-9*- mode10add0* imgsetDe=els'27- 973* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* 1-) ;egiones #e interes # -*- coding: utf-8 -*- """ Demonstrates a =ariety of uses for $<J This class pro=ides a user-ad(ustable region of interest mar%er Jt is possible to customi6e the layout and function of the scale"rotate handles in =ery flexible #ays """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import numpy as np ## .reate image to display arr 1 npones''977- 977*- dtype1float* arr2A>:>>- A>:>>3 1 7 arr22>- :3 1 > arr2:- 2>3 1 > arr2I>- :3 1 > arr2:- I>3 1 > arr2>7- :3 1 97 arr2:- >73 1 97 arr ?1 npsin'nplinspace'7- 27- 977**reshape'9- 977* arr ?1 nprandomnormal'si6e1'977-977** ## create ,GJ app 1 +t,ui+!pplication'23* # 1 pg,raphics5indo#'si6e1'9777-877*- border1True* #set5indo#Title'0pyqtgraph example: $<J &xamples0* text 1 """Data /election From JmageRbrBVn Drag an $<J or its handles to update the selected imageRbrB Qold .T$D #hile dragging to snap to pixel boundariesRbrB and 9>-degree rotation angles """ #9 1 #addDayout'ro#17- col17* label9 1 #9addDabel'text- ro#17- col17* =9a 1 #9addLie#8ox'ro#19- col17- loc%!spect1True* =9b 1 #9addLie#8ox'ro#12- col17- loc%!spect1True* img9a 1 pgJmageJtem'arr* =9aaddJtem'img9a* img9b 1 pgJmageJtem'* =9baddJtem'img9b* =9adisable!uto$ange'0xy0* =9bdisable!uto$ange'0xy0* =9aauto$ange'* =9bauto$ange'* rois 1 23 roisappend'pg$ect$<J'227- 273- 227- 273- pen1'7-M*** rois2-93add$otateQandle'29-73- 27>- 7>3* roisappend'pgDine$<J'27- :73- 227- 873- #idth1>- pen1'9-M*** roisappend'pg4ulti$ect$<J'2227- M73- 2>7- :73- 2:7- M733- #idth1>- pen1'2-M*** roisappend'pg&llipse$<J'2:7- 973- 2@7- 273- pen1'@-M*** roisappend'pg.ircle$<J'287- >73- 227- 273- pen1'A-M*** #roisappend'pgDine/egment$<J'22997- >73- 227- 2733- pen1'>-M*** roisappend'pg;olyDine$<J'2287- :73- 2M7- @73- 2:7- A733- pen1':-M*- closed1True** def update'roi*: img9bsetJmage'roiget!rray$egion'arr- img9a*- le=els1'7- arrmax'*** =9bauto$ange'*
for roi in rois: roisig$egion.hangedconnect'update* =9aaddJtem'roi* update'rois2-93*
text 1 """Gser-4odifiable $<JsRbrB .lic% on a line segment to add a ne# handle $ight clic% on a handle to remo=e """ #2 1 #addDayout'ro#17- col19* label2 1 #2addDabel'text- ro#17- col17* =2a 1 #2addLie#8ox'ro#19- col17- loc%!spect1True* r2a 1 pg;olyDine$<J'227-73- 297-973- 297-@73- 2@7-9733- closed1True* =2aaddJtem'r2a* r2b 1 pg;olyDine$<J'227--273- 297--973- 297--@733- closed1False* =2aaddJtem'r2b* =2adisable!uto$ange'0xy0* #=2bdisable!uto$ange'0xy0* =2aauto$ange'* #=2bauto$ange'* text 1 """8uilding custom $<J typesR8rB $<Js can be built #ith a =ariety of different handle typesRbrB that scale and rotate the roi around an arbitrary center location """ #@ 1 #addDayout'ro#19- col17* label@ 1 #@addDabel'text- ro#17- col17* =@ 1 #@addLie#8ox'ro#19- col17- loc%!spect1True* r@a 1 pg$<J'27-73- 297-973* =@addJtem'r@a* ## handles scaling hori6ontally around center r@aadd/caleQandle'29- 7>3- 27>- 7>3* r@aadd/caleQandle'27- 7>3- 27>- 7>3* ## handles scaling =ertically from opposite edge r@aadd/caleQandle'27>- 73- 27>- 93* r@aadd/caleQandle'27>- 93- 27>- 73* ## handles scaling both =ertically and hori6ontally r@aadd/caleQandle'29- 93- 27- 73* r@aadd/caleQandle'27- 73- 29- 93* r@b 1 pg$<J'227-73- 297-973* =@addJtem'r@b* ## handles rotating around center r@badd$otateQandle'29- 93- 27>- 7>3* r@badd$otateQandle'27- 73- 27>- 7>3* ## handles rotating around opposite corner r@badd$otateQandle'29- 73- 27- 93* r@badd$otateQandle'27- 93- 29- 73* ## handles rotating"scaling around center r@badd/cale$otateQandle'27- 7>3- 27>- 7>3* r@badd/cale$otateQandle'29- 7>3- 27>- 7>3* =@disable!uto$ange'0xy0* =@auto$ange'* text 1 """Transforming ob(ects #ith $<J""" #A 1 #addDayout'ro#19- col19* labelA 1 #AaddDabel'text- ro#17- col17* =A 1 #AaddLie#8ox'ro#19- col17- loc%!spect1True* g 1 pg,ridJtem'* =AaddJtem'g* rA 1 pg$<J'27-73- 2977-9773* rAadd$otateQandle'29-73- 27>- 7>3* rAadd$otateQandle'27-93- 27>- 7>3* imgA 1 pgJmageJtem'arr* =AaddJtem'rA* imgAset;arentJtem'rA* =Adisable!uto$ange'0xy0* =Aauto$ange'* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* 1/) &como#ar graficos """ Demonstrate the use of layouts to control placement of multiple plots " =ie#s " labels """ ## !dd path to library '(ust for examples) you do not need this* import init&xample from pyqtgraph+t import +t,ui- +t.ore import pyqtgraph as pg import numpy as np app 1 +t,ui+!pplication'23* =ie# 1 pg,raphicsLie#'* l 1 pg,raphicsDayout'border1'977-977-977** =ie#set.entralJtem'l* =ie#sho#'* =ie#set5indo#Title'0pyqtgraph example: ,raphicsDayout0* =ie#resi6e'877-:77* ## Title at top text 1 """ This example demonstrates the use of ,raphicsDayout to arrange items in a gridRbrB The items added to the layout must be subclasses of +,raphics5idget 'this includes RbrB ;lotJtem- Lie#8ox- DabelJtem- and ,rphicsDayout itself* """ laddDabel'text- col19- colspan1A* lnext$o#'* ## ;ut =ertical label on left side laddDabel'0Dong Lertical Dabel0- angle1-M7- ro#span1@* ## !dd @ plots into the first ro# 'automatic position* p9 1 ladd;lot'title1";lot 9"* p2 1 ladd;lot'title1";lot 2"* =b 1 laddLie#8ox'loc%!spect1True* img 1 pgJmageJtem'nprandomnormal'si6e1'977-977*** =baddJtem'img* =bauto$ange'* ## !dd a sub-layout into the second ro# 'automatic position* ## The added item should a=oid the first column- #hich is already filled lnext$o#'* l2 1 laddDayout'colspan1@- border1'>7-7-7** l2set.ontents4argins'97- 97- 97- 97* l2addDabel'"/ub-layout: this layout demonstrates the use of shared axes and axis labels"- colspan1@* l2next$o#'* l2addDabel'0Lertical !xis Dabel0- angle1-M7- ro#span12* p29 1 l2add;lot'* p22 1 l2add;lot'* l2next$o#'* p2@ 1 l2add;lot'* p2A 1 l2add;lot'* l2next$o#'* l2addDabel'"Qori6ontal!xisDabel"- col19- colspan12* ## hide axes on some plots p29hide!xis'0bottom0* p22hide!xis'0bottom0* p22hide!xis'0left0* p2Ahide!xis'0left0* p29hide8uttons'* p22hide8uttons'* p2@hide8uttons'* p2Ahide8uttons'* ## !dd 2 more plots into the third ro# 'manual position* pA 1 ladd;lot'ro#1@- col19* p> 1 ladd;lot'ro#1@- col12- colspan12* ## sho# some content in the plots p9plot'29-@-2-A-@->3* p2plot'29-@-2-A-@->3* pAplot'29-@-2-A-@->3* p>plot'29-@-2-A-@->3* ## /tart +t e=ent loop unless running in interacti=e mode if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* 11) Legen#7tem # -*- coding: utf-8 -*- """ Demonstrates basic use of DegendJtem """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui plt 1 pgplot'* pltset5indo#Title'0pyqtgraph example: Degend0* pltaddDegend'* #l 1 pgDegendJtem''977-:7*- offset1'I7-@7** # args are 'si6e- offset* #lset;arentJtem'pltgraphicsJtem'** # Cote #e do C<T call pltaddJtem in this case c9 1 pltplot'29-@-2-A3- pen10r0- name10red plot0* c2 1 pltplot'22-9-A-@3- pen10g0- fillDe=el17- fill8rush1'2>>-2>>-2>>-@7*- name10green plot0* #laddJtem'c9- 0red plot0* #laddJtem'c2- 0green plot0* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* !3) "e<t 7tem # -*- coding: utf-8 -*- """ This example sho#s ho# to insert text into a scene using TextJtem This class is for displaying text that is anchored to a particular location in the data coordinate system- but #hich is al#ays displayed unscaled For text that scales #ith the data- use +TextJtem For text that can be placed in a layout- use DabelJtem """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import numpy as np x 1 nplinspace'-27- 27- 9777* y 1 npsin'x* " x plot 1 pgplot'* ## create an empty plot #idget plotsetE$ange'-9- 2* plotset5indo#Title'0pyqtgraph example: text0* cur=e 1 plotplot'x-y* ## add a single cur=e ## .reate text ob(ect- use QT4D tags to specify color"si6e text 1 pgTextJtem'html10Rdi= style1"text-align: center"BRspan style1"color: #FFF)"BThis is theR"spanBRbrBRspan style1"color: #FF7) font-si6e: 9:pt)"B;&!UR"spanBR"di=B0- anchor1'-7@-9@*- border10#0- fill1'7- 7- 2>>- 977** plotaddJtem'text* textset;os'7- ymax'** ## Dra# an arro#head next to the text box arro# 1 pg!rro#Jtem'pos1'7- ymax'**- angle1-A>* plotaddJtem'arro#* ## /et up an animated arro# and text that trac% the cur=e cur=e;oint 1 pg.ur=e;oint'cur=e* plotaddJtem'cur=e;oint* text2 1 pgTextJtem'"test"- anchor1'7>- -97** text2set;arentJtem'cur=e;oint* arro#2 1 pg!rro#Jtem'angle1M7* arro#2set;arentJtem'cur=e;oint* ## update position e=ery 97ms index 1 7 def update'*: global cur=e;oint- index index 1 'index ? 9* H len'x* cur=e;ointset;os'float'index*"'len'x*-9** #text2=ie#$ange.hanged'* text2setText'02H79f- H79f30 H 'x2index3- y2index3**
timer 1 +t.ore+Timer'* timertimeoutconnect'update* timerstart'97* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* !1) =istas conecta#as # -*- coding: utf-8 -*- """ This example demonstrates the ability to lin% the axes of =ie#s together Lie#s can be lin%ed manually using the context menu- but only if they are gi=en names """ import init&xample ## !dd path to library '(ust for examples) you do not need this* from pyqtgraph+t import +t,ui- +t.ore import numpy as np import pyqtgraph as pg #+t,ui+!pplicationset,raphics/ystem'0raster0* app 1 +t,ui+!pplication'23* #m# 1 +t,ui+4ain5indo#'* #m#resi6e'877-877* x 1 nplinspace'->7- >7- 9777* y 1 npsin'x* " x #in 1 pg,raphics5indo#'title1"pyqtgraph example: Din%ed Lie#s"* #inresi6e'877-:77* #inaddDabel'"Din%ed Lie#s"- colspan12* #innext$o#'* p9 1 #inadd;lot'x1x- y1y- name1";lot9"- title1";lot9"* p2 1 #inadd;lot'x1x- y1y- name1";lot2"- title1";lot2: E lin%ed #ith ;lot9"* p2setDabel'0bottom0- "Dabel to test offset"* p2setEDin%'0;lot90* ## test lin%ing by name ## create plots @ and A out of order pA 1 #inadd;lot'x1x- y1y- name1";lotA"- title1";lotA: N -B ;lot@ 'deferred*- E -B ;lot9"- ro#12- col19* pAsetNDin%'0;lot@0* ## ;lot@ has not been created yet- but this should still #or% any#ay pAsetEDin%'p9* p@ 1 #inadd;lot'x1x- y1y- name1";lot@"- title1";lot@: N lin%ed #ith ;lot9"- ro#12- col17* p@setNDin%'p9* p@setDabel'0left0- "Dabel to test offset"* #+t,ui+!pplicationprocess&=ents'* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+!pplicationinstance'*execO'* !!) >lechas # -*- coding: utf-8 -*- """ Display an animated arro#head follo#ing a cur=e This example uses the .ur=e!rro# class- #hich is a combination of !rro#Jtem and .ur=e;oint To place a static arro# any#here in a scene- use !rro#Jtem To attach other types of item to a cur=e- use .ur=e;oint """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import numpy as np from pyqtgraph+t import +t,ui- +t.ore import pyqtgraph as pg app 1 +t,ui+!pplication'23* # 1 +t,ui+4ain5indo#'* c# 1 pg,raphicsDayout5idget'* #sho#'* #resi6e'A77-:77* #set.entral5idget'c#* #set5indo#Title'0pyqtgraph example: !rro#0* p 1 c#add;lot'ro#17- col17* p2 1 c#add;lot'ro#19- col17* ## =ariety of arro# shapes a9 1 pg!rro#Jtem'angle1-9:7- tip!ngle1:7- headDen1A7- tailDen1A7- tail5idth127- pen1S0color0: 0#0- 0#idth0: @T* a2 1 pg!rro#Jtem'angle1-927- tip!ngle1@7- base!ngle127- headDen1A7- tailDen1A7- tail5idth18- pen1Cone- brush10y0* a@ 1 pg!rro#Jtem'angle1-:7- tip!ngle1@7- base!ngle127- headDen1A7- tailDen1Cone- brush1Cone* aA 1 pg!rro#Jtem'angle1-27- tip!ngle1@7- base!ngle1-@7- headDen1A7- tailDen1Cone* a2set;os'97-7* a@set;os'27-7* aAset;os'@7-7* paddJtem'a9* paddJtem'a2* paddJtem'a@* paddJtem'aA* pset$ange'+t.ore+$ectF'-27- -97- :7- 27** ## !nimated arro# follo#ing cur=e c 1 p2plot'x1npsin'nplinspace'7- 2*nppi- 9777**- y1npcos'nplinspace'7- :*nppi- 9777*** a 1 pg.ur=e!rro#'c* p2addJtem'a* anim 1 ama%e!nimation'loop1-9* animstart'* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* !$) =ie:6o< #P"usr"bin"python # -*- coding: utf-8 -*- """ Lie#8ox is the general-purpose graphical container that allo#s the user to 6oom " pan to inspect any area of a 2D coordinate system This unimaginati=e example demonstrates the constrution of a Lie#8ox-based plot area #ith axes- =ery similar to the #ay ;lotJtem is built """ ## !dd path to library '(ust for examples) you do not need this* import init&xample ## This example uses a Lie#8ox to create a ;lot5idget-li%e interface #from scipy import random import numpy as np from pyqtgraph+t import +t,ui- +t.ore import pyqtgraph as pg app 1 +t,ui+!pplication'23* m# 1 +t,ui+4ain5indo#'* m#set5indo#Title'0pyqtgraph example: Lie#8ox0* m#sho#'* m#resi6e'877- :77* g= 1 pg,raphicsLie#'* m#set.entral5idget'g=* l 1 +t,ui+,raphics,ridDayout'* lsetQori6ontal/pacing'7* lsetLertical/pacing'7* =b 1 pgLie#8ox'* p9 1 pg;lotDataJtem'* =baddJtem'p9* ## Wust something to play #ith inside the Lie#8ox class mo=able$ect'+t,ui+,raphics$ectJtem*: def OOinitOO'self- *args*: +t,ui+,raphics$ectJtemOOinitOO'self- *args* selfset!cceptQo=er&=ents'True* def ho=er&nter&=ent'self- e=*: selfsa=ed;en 1 selfpen'* selfset;en'+t,ui+;en'+t,ui+.olor'2>>- 2>>- 2>>*** e=ignore'* def ho=erDea=e&=ent'self- e=*: selfset;en'selfsa=ed;en* e=ignore'* def mouse;ress&=ent'self- e=*: if e=button'* 11 +t.ore+tDeft8utton: e=accept'* selfpressDelta 1 selfmapTo;arent'e=pos'** - selfpos'* else: e=ignore'* def mouse4o=e&=ent'self- e=*: selfset;os'selfmapTo;arent'e=pos'** - selfpressDelta*
def updateData'*: yd- xd 1 rand'97777* p9setData'y1yd- x1xd* yd- xd 1 rand'97777* updateData'* =bauto$ange'* t 1 +t.ore+Timer'* ttimeoutconnect'updateData* tstart'>7* ## /tart +t e=ent loop unless running in interacti=e mode if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* !%) Graficos personali'a#os """ Demonstrate creation of a custom graphic 'a candlestic% plot* """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph import +t.ore- +t,ui ## .reate a subclass of ,raphics<b(ect ## The only required methods are paint'* and bounding$ect'* ## 'see +,raphicsJtem documentation* class .andlestic%Jtem'pg,raphics<b(ect*: def OOinitOO'self- data*: pg,raphics<b(ectOOinitOO'self* selfdata 1 data ## data must ha=e fields: time- open- close- min- max selfgenerate;icture'*
def generate;icture'self*: ## pre-computing a +;icture ob(ect allo#s paint'* to run much more quic%ly- ## rather than re-dra#ing the shapes e=ery time selfpicture 1 +t,ui+;icture'* p 1 +t,ui+;ainter'selfpicture* pset;en'pgm%;en'0#0** # 1 'selfdata293273 - selfdata273273* " @ for 't- open- close- min- max* in selfdata: pdra#Dine'+t.ore+;ointF't- min*- +t.ore+;ointF't- max** if open B close: pset8rush'pgm%8rush'0r0** else: pset8rush'pgm%8rush'0g0** pdra#$ect'+t.ore+$ectF't-#- open- #*2- close-open** pend'*
## /tart +t e=ent loop unless running in interacti=e mode if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* !-) $D )grafico #e superficie) # -*- coding: utf-8 -*- """ This example demonstrates the use of ,D/urface;lotJtem """ ## !dd path to library '(ust for examples) you do not need this* import init&xample from pyqtgraph+t import +t.ore- +t,ui import pyqtgraph as pg import pyqtgraphopengl as gl import scipyndimage as ndi import numpy as np ## .reate a ,D Lie# #idget to display data app 1 +t,ui+!pplication'23* # 1 gl,DLie#5idget'* #sho#'* #set5indo#Title'0pyqtgraph example: ,D/urface;lot0* #set.amera;osition'distance1>7* ## !dd a grid to the =ie# g 1 gl,D,ridJtem'* gscale'2-2-9* gsetDepthLalue'97* # dra# grid after surfaces since they may be translucent #addJtem'g* ## /imple surface plot example ## x- y =alues are not specified- so assumed to be 7:>7 6 1 ndigaussianOfilter'nprandomnormal'si6e1'>7->7**- '9-9** p9 1 gl,D/urface;lotJtem'616- shader10shaded0- color1'7>- 7>- 9- 9** p9scale'9:"AM- 9:"AM- 97* p9translate'-98- 2- 7* #addJtem'p9* ## /addle example #ith x and y specified x 1 nplinspace'-8- 8- >7* y 1 nplinspace'-8- 8- >7* 6 1 79 * ''xreshape'>7-9* ** 2* - 'yreshape'9->7* ** 2** p2 1 gl,D/urface;lotJtem'x1x- y1y- 616- shader10normal.olor0* p2translate'-97--97-7* #addJtem'p2* ## 4anually specified colors 6 1 ndigaussianOfilter'nprandomnormal'si6e1'>7->7**- '9-9** x 1 nplinspace'-92- 92- >7* y 1 nplinspace'-92- 92- >7* colors 1 npones''>7->7-A*- dtype1float* colors2-73 1 npclip'npcos'''xreshape'>7-9* ** 2* ? 'yreshape'9->7* ** 2** ** 7>*- 7- 9* colors2-93 1 colors2-73 p@ 1 gl,D/urface;lotJtem'616- colors1colorsreshape'>7*>7-A*- shader10shaded0- smooth1False* p@scale'9:"AM- 9:"AM- 97* p@translate'2- -98- 7* #addJtem'p@* ## !nimated example ## compute surface =ertex data cols 1 M7 ro#s 1 977 x 1 nplinspace'-8- 8- cols?9*reshape'cols?9-9* y 1 nplinspace'-8- 8- ro#s?9*reshape'9-ro#s?9* d 1 'x**2 ? y**2* * 79 d2 1 d ** 7> ? 79 ## precompute height =alues for all frames phi 1 nparange'7- nppi*2- nppi"27* 6 1 npsin'd2npne#axis-3 ? phireshape'phishape273- 9- 9** " d22npne#axis-3 ## create a surface plot- tell it to use the 0height.olor0 shader ## since this does not require normal =ectors to render 'thus #e ## can set computeCormals1False to sa=e time #hen the mesh updates* pA 1 gl,D/urface;lotJtem'x1x2:-73- y 1 y27-:3- shader10height.olor0- computeCormals1False- smooth1False* pAshader'*20color4ap03 1 nparray'272- 2- 7>- 72- 9- 9- 72- 7- 23* pAtranslate'97- 97- 7* #addJtem'pA* index 1 7 def update'*: global pA- 6- index index -1 9 pAsetData'6162indexH6shape2733*
timer 1 +t.ore+Timer'* timertimeoutconnect'update* timerstart'@7* ## /tart +t e=ent loop unless running in interacti=e mode if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* !/) $D )grafico #e #ispersion) # -*- coding: utf-8 -*- """ Demonstrates use of ,D/catter;lotJtem #ith rapidly-updating plots """ ## !dd path to library '(ust for examples) you do not need this* import init&xample from pyqtgraph+t import +t.ore- +t,ui import pyqtgraphopengl as gl import numpy as np app 1 +t,ui+!pplication'23* # 1 gl,DLie#5idget'* #opts20distance03 1 27 #sho#'* #set5indo#Title'0pyqtgraph example: ,D/catter;lotJtem0* g 1 gl,D,ridJtem'* #addJtem'g* ## ## First example is a set of points #ith px4ode1False ## These demonstrate the ability to ha=e points #ith real si6e do#n to a =ery small scale ## pos 1 npempty''>@- @** si6e 1 npempty''>@** color 1 npempty''>@- A** pos273 1 '9-7-7*) si6e273 1 7>) color273 1 '97- 77- 77- 7>* pos293 1 '7-9-7*) si6e293 1 72) color293 1 '77- 77- 97- 7>* pos223 1 '7-7-9*) si6e223 1 2"@) color223 1 '77- 97- 77- 7>* 6 1 7> d 1 :7 for i in range'@->@*: pos2i3 1 '7-7-6* si6e2i3 1 2"d color2i3 1 '77- 97- 77- 7>* 6 *1 7> d *1 27
sp9 1 gl,D/catter;lotJtem'pos1pos- si6e1si6e- color1color- px4ode1False* sp9translate'>->-7* #addJtem'sp9* ## ## /econd example sho#s a =olume of points #ith rapidly updating color ## and px4ode1True ## pos 1 nprandomrandom'si6e1'977777-@** pos *1 297--97-973 pos273 1 '7-7-7* color 1 npones''posshape273- A** d2 1 'pos**2*sum'axis19***7> si6e 1 nprandomrandom'si6e1posshape273**97 sp2 1 gl,D/catter;lotJtem'pos1pos- color1'9-9-9-9*- si6e1si6e* phase 1 7 #addJtem'sp2* ## ## Third example sho#s a grid of points #ith rapidly updating position ## and px4ode 1 False ## pos@ 1 np6eros''977-977-@** pos@2:-:-:23 1 npmgrid2:977- :9773transpose'9-2-7* * 2-79-793 pos@ 1 pos@reshape'97777-@* d@ 1 'pos@**2*sum'axis19***7> sp@ 1 gl,D/catter;lotJtem'pos1pos@- color1'9-9-9-@*- si6e179- px4ode1False* #addJtem'sp@* def update'*: ## update =olume colors global phase- sp2- d2 s 1 -npcos'd2*2?phase* color 1 npempty''len'd2*-A*- dtype1npfloat@2* color2:-@3 1 npclip's * 79- 7- 9* color2:-73 1 npclip's * @7- 7- 9* color2:-93 1 npclip's * 97- 7- 9* color2:-23 1 npclip's ** @- 7- 9* sp2setData'color1color* phase -1 79
## /tart +t e=ent loop unless running in interacti=e mode if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* $!) $D )imagen) # -*- coding: utf-8 -*- """ Gse ,DJmageJtem to display image data on rectangular planes Jn this example- the image data is sampled from a =olume and the image planes placed as if they slice through the =olume """ ## !dd path to library '(ust for examples) you do not need this* import init&xample from pyqtgraph+t import +t.ore- +t,ui import pyqtgraphopengl as gl import pyqtgraph as pg import numpy as np import scipyndimage as ndi app 1 +t,ui+!pplication'23* # 1 gl,DLie#5idget'* #opts20distance03 1 277 #sho#'* #set5indo#Title'0pyqtgraph example: ,DJmageJtem0* ## create =olume data set to slice three images from shape 1 '977-977-I7* data 1 ndigaussianOfilter'nprandomnormal'si6e1shape*- 'A-A-A** data ?1 ndigaussianOfilter'nprandomnormal'si6e1shape*- '9>-9>-9>***9> ## slice out three planes- con=ert to $,8! for <pen,D texture le=els 1 '-778- 778* tex9 1 pgma%e$,8!'data2shape273"23- le=els1le=els*273 # y6 plane tex2 1 pgma%e$,8!'data2:-shape293"23- le=els1le=els*273 # x6 plane tex@ 1 pgma%e$,8!'data2:-:-shape223"23- le=els1le=els*273 # xy plane #tex92:-:-@3 1 928 #tex22:-:-@3 1 928 #tex@2:-:-@3 1 928 ## .reate three image items from textures- add to =ie# =9 1 gl,DJmageJtem'tex9* =9translate'-shape293"2- -shape223"2- 7* =9rotate'M7- 7-7-9* =9rotate'-M7- 7-9-7* #addJtem'=9* =2 1 gl,DJmageJtem'tex2* =2translate'-shape273"2- -shape223"2- 7* =2rotate'-M7- 9-7-7* #addJtem'=2* =@ 1 gl,DJmageJtem'tex@* =@translate'-shape273"2- -shape293"2- 7* #addJtem'=@* ax 1 gl,D!xisJtem'* #addJtem'ax* ## /tart +t e=ent loop unless running in interacti=e mode if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* $$) Plot+i#get # -*- coding: utf-8 -*- """ Demonstrates use of ;lot5idget class This is little more than a ,raphicsLie# #ith a ;lotJtem placed in its center """ import init&xample ## !dd path to library '(ust for examples) you do not need this* from pyqtgraph+t import +t,ui- +t.ore import numpy as np import pyqtgraph as pg #+t,ui+!pplicationset,raphics/ystem'0raster0* app 1 +t,ui+!pplication'23* m# 1 +t,ui+4ain5indo#'* m#set5indo#Title'0pyqtgraph example: ;lot5idget0* m#resi6e'877-877* c# 1 +t,ui+5idget'* m#set.entral5idget'c#* l 1 +t,ui+L8oxDayout'* c#setDayout'l* p# 1 pg;lot5idget'name10;lot90* ## gi=ing the plots names allo#s us to lin% their axes together ladd5idget'p#* p#2 1 pg;lot5idget'name10;lot20* ladd5idget'p#2* p#@ 1 pg;lot5idget'* ladd5idget'p#@* m#sho#'* ## .reate an empty plot cur=e to be filled later- set its pen p9 1 p#plot'* p9set;en''277-277-977** ## !dd in some extra graphics rect 1 +t,ui+,raphics$ectJtem'+t.ore+$ectF'7- 7- 9- >e-99** rectset;en'+t,ui+;en'+t,ui+.olor'977- 277- 977*** p#addJtem'rect* p#setDabel'0left0- 0Lalue0- units10L0* p#setDabel'0bottom0- 0Time0- units10s0* p#setN$ange'7- 2* p#setE$ange'7- 9e-97* def rand'n*: data 1 nprandomrandom'n* data2int'n*79*:int'n*79@*3 ?1 > data2int'n*798*3 ?1 2 data2int'n*79*:int'n*79@*3 *1 > data2int'n*798*3 *1 27 data *1 9e-92 return data- nparange'n- n?len'data** " float'n*
def updateData'*: yd- xd 1 rand'97777* p9setData'y1yd- x1xd* ## /tart a timer to rapidly update the plot in p# t 1 +t.ore+Timer'* ttimeoutconnect'updateData* tstart'>7* #updateData'* ## 4ultiple parameteri6ed plots--#e can autogenerate a=erages for these for i in range'7- >*: for ( in range'7- @*: yd- xd 1 rand'97777* p#2plot'y1yd*'(?9*- x1xd- params1S0iter0: i- 0=al0: (T* ## Test large numbers cur=e 1 p#@plot'nprandomnormal'si6e1977**9e7- clic%able1True* cur=ecur=eset.lic%able'True* cur=eset;en'0#0* ## #hite pen cur=eset/hado#;en'pgm%;en''I7-I7-@7*- #idth1:- cosmetic1True** def clic%ed'*: print'"cur=e clic%ed"* cur=esig.lic%edconnect'clic%ed* lr 1 pgDinear$egionJtem'29- @73- bounds127-9773- mo=able1True* p#@addJtem'lr* line 1 pgJnfiniteDine'angle1M7- mo=able1True* p#@addJtem'line* lineset8ounds'27-2773* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* $%) Spin6o< # -*- coding: utf-8 -*- """ This example demonstrates the /pin8ox #idget- #hich is an extension of +Double/pin8ox pro=iding some ad=anced features: * /J-prefixed units * Con-linear stepping modes * 8ounded"unbounded =alues """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import numpy as np app 1 +t,ui+!pplication'23* spins 1 2 '"Floating-point spin box- min17- no maximum"- pg/pin8ox'=alue1>7- bounds127- Cone3**- '"Jnteger spin box- dec steppingRbrB'9-M- 97-M7- 977-M77- etc*"- pg/pin8ox'=alue197- int1True- dec1True- min/tep19- step19**- '"Float #ith /J-prefixed unitsRbrB'n- u- m- %- 4- etc*"- pg/pin8ox'=alue17M- suffix10L0- si;refix1True**- '"Float #ith /J-prefixed units-RbrBdec step179- min/tep179"- pg/pin8ox'=alue197- suffix10L0- si;refix1True- dec1True- step179- min/tep179**- '"Float #ith /J-prefixed units-RbrBdec step17>- min/tep1779"- pg/pin8ox'=alue197- suffix10L0- si;refix1True- dec1True- step17>- min/tep1779**- '"Float #ith /J-prefixed units-RbrBdec step197- min/tep17779"- pg/pin8ox'=alue197- suffix10L0- si;refix1True- dec1True- step197- min/tep17779**- 3 #in 1 +t,ui+4ain5indo#'* #inset5indo#Title'0pyqtgraph example: /pin8ox0* c# 1 +t,ui+5idget'* layout 1 +t,ui+,ridDayout'* c#setDayout'layout* #inset.entral5idget'c#* #insho#'* ##inresi6e'@77- :77* changingDabel 1 +t,ui+Dabel'* ## updated immediately changedDabel 1 +t,ui+Dabel'* ## updated only #hen editing is finished or mouse #heel has stopped for 7@sec changingDabelset4inimum5idth'277* font 1 changingDabelfont'* fontset8old'True* fontset;oint/i6e'9A* changingDabelsetFont'font* changedDabelsetFont'font* labels 1 23 def =alue.hanged'sb*: changedDabelsetText'"Final =alue: Hs" H str'sb=alue'*** def =alue.hanging'sb- =alue*: changingDabelsetText'"Lalue changing: Hs" H str'sb=alue'***
for text- spin in spins: label 1 +t,ui+Dabel'text* labelsappend'label* layoutadd5idget'label* layoutadd5idget'spin* spinsigLalue.hangedconnect'=alue.hanged* spinsigLalue.hangingconnect'=alue.hanging* layoutadd5idget'changingDabel- 7- 9* layoutadd5idget'changedDabel- 2- 9* #def m%5in'*: ##in 1 +t,ui+4ain5indo#'* #g 1 +t,ui+FormDayout'* ## 1 +t,ui+5idget'* ##setDayout'g* ##inset.entral5idget'#* #s9 1 /pin8ox'=alue1>- step179- bounds12-9>- Cone3- suffix10units0* #t9 1 +t,ui+Dine&dit'* #gadd$o#'s9- t9* #s2 1 /pin8ox'=alue197e-:- dec1True- step179- min/tep19e-:- suffix10!0- si;refix1True* #t2 1 +t,ui+Dine&dit'* #gadd$o#'s2- t2* #s@ 1 /pin8ox'=alue19777- dec1True- step17>- min/tep19e-:- bounds129- 9eM3- suffix10Q60- si;refix1True* #t@ 1 +t,ui+Dine&dit'* #gadd$o#'s@- t@* #sA 1 /pin8ox'int1True- dec1True- step19- min/tep19- bounds12-97- 97773* #tA 1 +t,ui+Dine&dit'* #gadd$o#'sA- tA* ##insho#'* #import sys #for sb in 2s9- s2- s@-sA3: ##+t.ore+<b(ectconnect'sb- +t.ore/J,C!D'0=alue.hanged'double*0*- lambda =: sysstdout#rite'str'sb* ? " =alue.hangedVn"** ##+t.ore+<b(ectconnect'sb- +t.ore/J,C!D'0editingFinished'*0*- lambda: sysstdout#rite'str'sb* ? " editingFinishedVn"** #sbsigLalue.hangedconnect'=alue.hanged* #sbsigLalue.hangingconnect'=alue.hanging* #sbeditingFinishedconnect'lambda: sysstdout#rite'str'sb* ? " editingFinishedVn"** #return #in- #- 2s9- s2- s@- sA3 #a 1 m%5in'* #def test'n1977*: #for i in range'n*: ##in- #- sb 1 m%5in'* #for s in sb: ##set;arent'Cone* #sset;arent'Cone* #s=alue.hangeddisconnect'* #seditingFinisheddisconnect'* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* $() .onsole+i#get # -*- coding: utf-8 -*- """ .onsole5idget is used to allo# execution of user-supplied python commands in an application Jt also includes a command history and functionality for trapping and inspecting stac% traces """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import numpy as np import pyqtgraphconsole app 1 pgm%+!pp'* ## build an initial namespace for console commands to be executed in 'this is optional) ## the user can al#ays import these modules manually* namespace 1 S0pg0: pg- 0np0: npT ## initial text to display in the console text 1 """ This is an interacti=e python console The numpy and pyqtgraph modules ha=e already been imported as 0np0 and 0pg0 ,o- play """ c 1 pyqtgraphconsole.onsole5idget'namespace1namespace- text1text* csho#'* cset5indo#Title'0pyqtgraph example: .onsole5idget0* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* $*) 0istograma # -*- coding: utf-8 -*- """ Gse a QistogramDGT5idget to control the contrast " coloration of an image """ ## !dd path to library '(ust for examples) you do not need this* import init&xample import numpy as np import scipyndimage as ndi from pyqtgraph+t import +t,ui- +t.ore import pyqtgraph as pg app 1 +t,ui+!pplication'23* #in 1 +t,ui+4ain5indo#'* #inresi6e'877-:77* #insho#'* #inset5indo#Title'0pyqtgraph example: Qistogram DGT0* c# 1 +t,ui+5idget'* #inset.entral5idget'c#* l 1 +t,ui+,ridDayout'* c#setDayout'l* lset/pacing'7* = 1 pg,raphicsLie#'* =b 1 pgLie#8ox'* =bset!spectDoc%ed'* =set.entralJtem'=b* ladd5idget'=- 7- 7* # 1 pgQistogramDGT5idget'* ladd5idget'#- 7- 9* data 1 ndigaussianOfilter'nprandomnormal'si6e1'2>:- 2>:**- '27- 27** for i in range'@2*: for ( in range'@2*: data2i*8- (*83 ?1 9 img 1 pgJmageJtem'data* #data2 1 np6eros''2-* ? datashape ? '2-** #data227-:-:-73 1 data ## ma%e non-contiguous array for testing purposes #img 1 pgJmageJtem'data227-:-:-73* =baddJtem'img* =bauto$ange'* #setJmageJtem'img* ## /tart +t e=ent loop unless running in interacti=e mode if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* $-) "ree+i#get # -*- coding: utf-8 -*- """ /imple demonstration of Tree5idget- #hich is an extension of +Tree5idget that allo#s #idgets to be added and dragged #ithin the tree more easily """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import numpy as np app 1 +t,ui+!pplication'23* # 1 pgTree5idget'* #set.olumn.ount'2* #sho#'* #set5indo#Title'0pyqtgraph example: Tree5idget0* i9 1 +t,ui+Tree5idgetJtem'2"Jtem 9"3* i99 1 +t,ui+Tree5idgetJtem'2"Jtem 99"3* i92 1 +t,ui+Tree5idgetJtem'2"Jtem 92"3* i2 1 +t,ui+Tree5idgetJtem'2"Jtem 2"3* i29 1 +t,ui+Tree5idgetJtem'2"Jtem 29"3* i299 1 pgTree5idgetJtem'2"Jtem 299"3* i292 1 pgTree5idgetJtem'2"Jtem 292"3* i22 1 pgTree5idgetJtem'2"Jtem 22"3* i@ 1 pgTree5idgetJtem'2"Jtem @"3* iA 1 pgTree5idgetJtem'2"Jtem A"3* i> 1 pgTree5idgetJtem'2"Jtem >"3* b> 1 +t,ui+;ush8utton'08utton0* i>set5idget'9- b>* #addTopDe=elJtem'i9* #addTopDe=elJtem'i2* #addTopDe=elJtem'i@* #addTopDe=elJtem'iA* #addTopDe=elJtem'i>* i9add.hild'i99* i9add.hild'i92* i2add.hild'i29* i29add.hild'i299* i29add.hild'i292* i2add.hild'i22* b9 1 +t,ui+;ush8utton'"8utton"* #setJtem5idget'i9- 9- b9* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* $/) Data"ree+i#get # -*- coding: utf-8 -*- """ /imple use of DataTree5idget to display a structure of nested dicts- lists- and arrays """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import numpy as np app 1 +t,ui+!pplication'23* d 1 S 0list90: 29-2-@-A->-:- S0nested90: 0aaaaa0- 0nested20: 0bbbbb0T- "se=en"3- 0dict90: S 0x0: 9- 0y0: 2- 060: 0three0 T- 0array9 '27x27*0: npones''97-97** T tree 1 pgDataTree5idget'data1d* treesho#'* treeset5indo#Title'0pyqtgraph example: DataTree5idget0* treeresi6e':77-:77* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* $1) Gra#ient+i#get # -*- coding: utf-8 -*- """ Demonstrates the appearance " interacti=ity of ,radient5idget '#ithout actually doing anything useful #ith it* """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import numpy as np app 1 +t,ui+!pplication'23* # 1 +t,ui+4ain5indo#'* #sho#'* #set5indo#Title'0pyqtgraph example: ,radient5idget0* #resi6e'A77-A77* c# 1 +t,ui+5idget'* #set.entral5idget'c#* l 1 +t,ui+,ridDayout'* lset/pacing'7* c#setDayout'l* #9 1 pg,radient5idget'orientation10top0* #2 1 pg,radient5idget'orientation10right0- allo#!dd1False* ##2setTic%.olor'9- +t,ui+.olor'2>>-2>>-2>>** #@ 1 pg,radient5idget'orientation10bottom0* #A 1 pg,radient5idget'orientation10left0* #Aload;reset'0spectrum0* label 1 +t,ui+Dabel'""" - .lic% a triangle to change its color - Drag triangles to mo=e - .lic% in an empty area to add a ne# color 'adding is disabled for the right-side #idget* - $ight clic% a triangle to remo=e """* ladd5idget'#9- 7- 9* ladd5idget'#2- 9- 2* ladd5idget'#@- 2- 9* ladd5idget'#A- 9- 7* ladd5idget'label- 9- 9* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+!pplicationinstance'*execO'* %3) "a,le+i#get # -*- coding: utf-8 -*- """ /imple demonstration of Table5idget- #hich is an extension of +Table5idget that automatically displays a =ariety of tabluar data formats """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import numpy as np app 1 +t,ui+!pplication'23* # 1 pgTable5idget'* #sho#'* #resi6e'>77->77* #set5indo#Title'0pyqtgraph example: Table5idget0*
#setData'data* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* %1) .olor6utton # -*- coding: utf-8 -*- """ /imple example demonstrating a button #hich displays a colored rectangle and allo#s the user to select a ne# color by clic%ing on the button """ import init&xample ## !dd path to library '(ust for examples) you do not need this* import pyqtgraph as pg from pyqtgraph+t import +t.ore- +t,ui import numpy as np app 1 +t,ui+!pplication'23* #in 1 +t,ui+4ain5indo#'* btn 1 pg.olor8utton'* #inset.entral5idget'btn* #insho#'* #inset5indo#Title'0pyqtgraph example: .olor8utton0* def change'btn*: print'"change"- btncolor'** def done'btn*: print'"done"- btncolor'** btnsig.olor.hangingconnect'change* btnsig.olor.hangedconnect'done* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* %!) Joystic?6utton # -*- coding: utf-8 -*- """ Woystic%8utton is a button #ith x"y =alues 5hen the button is depressed and the mouse dragged- the x"y =alues change to follo# the mouse 5hen the mouse button is released- the x"y =alues change to 7-7 'rather li%e letting go of the (oystic%* """ import init&xample ## !dd path to library '(ust for examples) you do not need this* from pyqtgraph+t import +t,ui- +t.ore import pyqtgraph as pg app 1 +t,ui+!pplication'23* m# 1 +t,ui+4ain5indo#'* m#resi6e'@77->7* m#set5indo#Title'0pyqtgraph example: Woystic%8utton0* c# 1 +t,ui+5idget'* m#set.entral5idget'c#* layout 1 +t,ui+,ridDayout'* c#setDayout'layout* m#sho#'* l9 1 pgLalueDabel'si;refix1True- suffix10m0* l2 1 pgLalueDabel'si;refix1True- suffix10m0* (b 1 pgWoystic%8utton'* (bsetFixed5idth'@7* (bsetFixedQeight'@7* layoutadd5idget'l9- 7- 7* layoutadd5idget'l2- 7- 9* layoutadd5idget'(b- 7- 2* x 1 7 y 1 7 def update'*: global x- y- l9- l2- (b dx- dy 1 (bget/tate'* x ?1 dx * 9e-@ y ?1 dy * 9e-@ l9setLalue'x* l2setLalue'y* timer 1 +t.ore+Timer'* timertimeoutconnect'update* timerstart'@7* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* %$) Diagrama #e flu2o # -*- coding: utf-8 -*- """ This example demonstrates a =ery basic use of flo#charts: filter data- displaying both the input and output of the filter The beha=ior of he filter can be reprogrammed by the user 8asic steps are: - create a flo#chart and t#o plots - input noisy data to the flo#chart - flo#chart connects data to the first plot- #here it is displayed - add a gaussian filter to lo#pass the data- then display it in the second plot """ import init&xample ## !dd path to library '(ust for examples) you do not need this* from pyqtgraphflo#chart import Flo#chart from pyqtgraph+t import +t,ui- +t.ore import pyqtgraph as pg import numpy as np import pyqtgraphmetaarray as metaarray app 1 +t,ui+!pplication'23* ## .reate main #indo# #ith grid layout #in 1 +t,ui+4ain5indo#'* #inset5indo#Title'0pyqtgraph example: Flo#chart0* c# 1 +t,ui+5idget'* #inset.entral5idget'c#* layout 1 +t,ui+,ridDayout'* c#setDayout'layout* ## .reate flo#chart- define input"output terminals fc 1 Flo#chart'terminals1S 0dataJn0: S0io0: 0in0T- 0data<ut0: S0io0: 0out0T T* # 1 fc#idget'* ## !dd flo#chart control panel to the main #indo# layoutadd5idget'fc#idget'*- 7- 7- 2- 9* ## !dd t#o plot #idgets p#9 1 pg;lot5idget'* p#2 1 pg;lot5idget'* layoutadd5idget'p#9- 7- 9* layoutadd5idget'p#2- 9- 9* #insho#'* ## generate signal data to pass through the flo#chart data 1 nprandomnormal'si6e19777* data2277:@773 ?1 9 data ?1 npsin'nplinspace'7- 977- 9777** data 1 metaarray4eta!rray'data- info12S0name0: 0Time0- 0=alues0: nplinspace'7- 97- len'data**T- ST3* ## Feed data into the input terminal of the flo#chart fcsetJnput'dataJn1data* ## populate the flo#chart #ith a basic set of processing nodes ## 'usually #e let the user do this* p#9Code 1 fccreateCode'0;lot5idget0- pos1'7- -9>7** p#9Codeset;lot'p#9* p#2Code 1 fccreateCode'0;lot5idget0- pos1'9>7- -9>7** p#2Codeset;lot'p#2* fCode 1 fccreateCode'0,aussianFilter0- pos1'7- 7** fCodectrls20sigma03setLalue'>* fcconnectTerminals'fc20dataJn03- fCode20Jn03* fcconnectTerminals'fc20dataJn03- p#9Code20Jn03* fcconnectTerminals'fCode20<ut03- p#2Code20Jn03* fcconnectTerminals'fCode20<ut03- fc20data<ut03* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'* %%) Diagrama #e flu2o con no#os personali'a#os # -*- coding: utf-8 -*- """ This example demonstrates #riting a custom Code subclass for use #ith flo#charts 5e implement a couple of simple image processing nodes """ import init&xample ## !dd path to library '(ust for examples) you do not need this* from pyqtgraphflo#chart import Flo#chart- Code import pyqtgraphflo#chartlibrary as fclib from pyqtgraphflo#chartlibrarycommon import .trlCode from pyqtgraph+t import +t,ui- +t.ore import pyqtgraph as pg import numpy as np import scipyndimage app 1 +t,ui+!pplication'23* ## .reate main #indo# #ith a grid layout inside #in 1 +t,ui+4ain5indo#'* #inset5indo#Title'0pyqtgraph example: Flo#chart.ustomCode0* c# 1 +t,ui+5idget'* #inset.entral5idget'c#* layout 1 +t,ui+,ridDayout'* c#setDayout'layout* ## .reate an empty flo#chart #ith a single input and output fc 1 Flo#chart'terminals1S 0dataJn0: S0io0: 0in0T- 0data<ut0: S0io0: 0out0T T* # 1 fc#idget'* layoutadd5idget'fc#idget'*- 7- 7- 2- 9* ## .reate t#o JmageLie# #idgets to display the ra# and processed data #ith contrast ## and color control =9 1 pgJmageLie#'* =2 1 pgJmageLie#'* layoutadd5idget'=9- 7- 9* layoutadd5idget'=2- 9- 9* #insho#'* ## generate random input data data 1 nprandomnormal'si6e1'977-977** data 1 2> * scipyndimagegaussianOfilter'data- '>->** data ?1 nprandomnormal'si6e1'977-977** data2A7::7- A7::73 ?1 9>7 data2@7:>7- @7:>73 ?1 9>7 #data ?1 npsin'nplinspace'7- 977- 9777** #data 1 metaarray4eta!rray'data- info12S0name0: 0Time0- 0=alues0: nplinspace'7- 97- len'data**T- ST3* ## /et the ra# data as the input =alue to the flo#chart fcsetJnput'dataJn1data* ## !t this point- #e need some custom Code classes since those pro=ided in the library ## are not sufficient &ach node #ill define a set of input"output terminals- a ## processing function- and optionally a control #idget 'to be displayed in the ## flo#chart control panel* class JmageLie#Code'Code*: """Code that displays image data in an JmageLie# #idget""" nodeCame 1 0JmageLie#0
def OOinitOO'self- name*: self=ie# 1 Cone ## Jnitiali6e node #ith only a single input terminal CodeOOinitOO'self- name- terminals1S0data0: S0io0:0in0TT*
def setLie#'self- =ie#*: ## setLie# must be called by the program self=ie# 1 =ie#
def process'self- data- display1True*: ## if process is called #ith display1False- then the flo#chart is being operated ## in batch processing mode- so #e should s%ip displaying to impro=e performance
if display and self=ie# is not Cone: ## the 0data0 argument is the =alue gi=en to the 0data0 terminal if data is Cone: self=ie#setJmage'np6eros''9-9*** # gi=e a blan% array to clear the =ie# else: self=ie#setJmage'data* ## register the class so it #ill appear in the menu of node types ## Jt #ill appear in the 0display0 sub-menu fclibregisterCodeType'JmageLie#Code- 2'0Display0-*3*
## 5e #ill define an unsharp mas%ing filter node as a subclass of .trlCode ## .trlCode is (ust a con=enience class that automatically creates its ## control #idget based on a simple data structure class Gnsharp4as%Code'.trlCode*: """$eturn the input data passed through scipyndimagegaussianOfilter""" nodeCame 1 "Gnsharp4as%" uiTemplate 1 2 '0sigma0- 0spin0- S0=alue0: 97- 0step0: 97- 0range0: 277- Cone3T*- '0strength0- 0spin0- S0=alue0: 97- 0dec0: True- 0step0: 7>- 0min/tep0: 779- 0range0: 277- Cone3T*- 3 def OOinitOO'self- name*: ## Define the input " output terminals a=ailable on this node terminals 1 S 0dataJn0: dict'io10in0*- # each terminal needs at least a name and 0data<ut0: dict'io10out0*- # to specify #hether it is input or output T # other more ad=anced options are a=ailable # as #ell
.trlCodeOOinitOO'self- name- terminals1terminals*
def process'self- dataJn- display1True*: # .trlCode has created selfctrls- #hich is a dict containing SctrlCame: #idgetT sigma 1 selfctrls20sigma03=alue'* strength 1 selfctrls20strength03=alue'* output 1 dataJn - 'strength * scipyndimagegaussianOfilter'dataJn- 'sigma-sigma*** return S0data<ut0: outputT
## register the class so it #ill appear in the menu of node types ## Jt #ill appear in a ne# 0image0 sub-menu fclibregisterCodeType'Gnsharp4as%Code- 2'0Jmage0-*3*
## Co# #e #ill programmatically add nodes to define the function of the flo#chart ## Cormally- the user #ill do this manually or by loading a pre-generated ## flo#chart file =9Code 1 fccreateCode'0JmageLie#0- pos1'7- -9>7** =9CodesetLie#'=9* =2Code 1 fccreateCode'0JmageLie#0- pos1'9>7- -9>7** =2CodesetLie#'=2* fCode 1 fccreateCode'0Gnsharp4as%0- pos1'7- 7** fcconnectTerminals'fc20dataJn03- fCode20dataJn03* fcconnectTerminals'fc20dataJn03- =9Code20data03* fcconnectTerminals'fCode20data<ut03- =2Code20data03* fcconnectTerminals'fCode20data<ut03- fc20data<ut03* ## /tart +t e=ent loop unless running in interacti=e mode or using pyside if OOnameOO 11 0OOmainOO0: import sys if 'sysflagsinteracti=e P1 9* or not hasattr'+t.ore- 0;E+TOL&$/J<C0*: +t,ui+applicationinstance'*execO'*