Python PYQT drawing histograms

Source: Internet
Author: User

#-*-coding:utf-8-*-"""In this example we draw the different kinds of histogram.""" fromQtpyImportqtwidgets, Qtgui, Qtcore fromQtpy. QtwidgetsImportqapplication, QwidgetImportdatetime as DT fromVnpy.traderImport* fromVnpy.trader.uiKLineImport* fromVnpy.trader.widget.crosshairToolImportCrosshairtoolImportPyqtgraph as PGImportNumPy as NPImportMatplotlib.pyplot as PltImportMatplotlib.mlab as MlabImportSYSclassHistogramlutwidget (qwidget):def __init__(Self, data, parent=None): Self.parent=Parent Self.data=Data Super (Histogramlutwidget, self).__init__(parent)#Inheritance    #Interface Layoutself.pw=pg. Plotwidget () Self.lay_kl= pg. Graphicslayout (border= (100, 100, 100)) Self.lay_KL.setContentsMargins (10, 10, 10, 10) self.lay_KL.setSpacing (0) self.lay_KL.setBorder (color= (255, 255, 255, 255), width=0.8) self.lay_KL.setZValue (0) Self.pw.setCentralItem (SELF.LAY_KL)## Set the horizontal axis    #xdict = dict (Enumerate (self.data["Timelist"]))    #self.axistime = Mystringaxis (xdict, orientation= ' bottom ')    ## Initialize the sub-diagramSELF.INITPLOTPNL ()## Register Cross cursorx=[] Viwe=self.plt Self.crosshair=Crosshairtool (SELF.PW, X, Viwe, self)#Setup InterfaceSelf.vb =qtwidgets.qvboxlayout () self.vb.addWidget (SELF.PW) self.setlayout (Self.vb)# ----------------------------------------------------------------------    defINITPLOTPNL (self, xmin=0, xmax=-1): Vals=Np.hstack (self.data) xMin=min (self.data) Xmax=Max (Self.data)#Histogram        #y, x = Np.histogram (Vals, Bins=np.linspace (Xmin,xmax, +), normed=false,density=true)        ##histNX, xbins, Ptchs = Plt.hist (Self.data, bins=50, Normed=true, facecolor='Black', edgecolor='Black', Alpha=1,histtype ='Bar') Histo= Plt.hist (Self.data, 50) VB=Customviewbox ()#SELF.PLT=PG. Plotitem (VIEWBOX=VB, axisitems={' bottom ': self.axistime}) #设置x轴Self.plt = pg. Plotitem (viewbox=vb) leng_=Len (self.data) self.plt.setRange (XRange= (0, leng_), yrange=(XMin, xmax))##histogram        #self.plt.plot (x, Y, Stepmode=true, filllevel=0, brush= (0, 0, 255, y), size=0.4) #绘制统计所得到的概率密度, histogram, no boundary split line        ##hist Barwidth = xbins[1]-xbins[0]#Width of each bin.        #Self.plt.plot (x,y,width=width) # The probability density obtained by plotting statistics, line graphSelf.pi=pg. Bargraphitem (X=histo[1][0:50],height=histo[0],width=width, color='y',)#the probability density obtained by drawing statistics, bar graphSelf.plt.addItem (Self.pi) Self.lay_KL.addItem (SELF.PLT)defRefresh (self):"""Refresh the actual extent of the sub-graph"""Leng_=Len (self.data) xMin=min (self.data) Xmax=Max (Self.data) self.plt.setRange (XRange= (0, leng_), yrange=(XMin, xmax))if __name__=='__main__': App=qapplication (SYS.ARGV) ex=Histogramlutwidget () sys.exit (App.exec_ ())

# # # #才接触, the project is not carefully studied, there are mistakes in the correction of the place, I hope you are not hesitate to point out

Python PYQT drawing histograms

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.