使用PyQtGraph绘制精美的股票行情K线图

更新时间:2023-07-20 19:34:44 阅读: 评论:0

使⽤PyQtGraph绘制精美的股票⾏情K线图
南海是中国的吗>夜视仪望远镜
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'QWidget_plot.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
import sys
reload(sys)
sys.tdefaultencoding('utf-8')
from PyQt4 import QtCore, QtGui蘑菇怎么种
import datetime
import pyqtgraph as pg
import tushare as ts
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def_fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def_translate(context, text, disambig):
return anslate(context, text, disambig, _encoding)
except AttributeError:
def_translate(context, text, disambig):
return anslate(context, text, disambig)
class Ui_MainWindow(object):
def tupUi(lf, MainWindow):
MainWindow.tObjectName(_fromUtf8("MainWindow"))
lf.verticalLayout_2 = QtGui.alwidget)
lf.verticalLayout_2.tObjectName(_fromUtf8("verticalLayout"))
lf.verticalLayout_2.tObjectName(_fromUtf8("verticalLayout_2"))
lf.verticalLayout_2.tContentsMargins(0,0,0,0)
MainWindow.alwidget)
MainWindow.ubar)
lf.drawChart = DrawChart(ktype='D')
lf.verticalLayout_2.addWidget(lf.drawChart.pyqtgraphDrawChart())
tSlotsByName(MainWindow)
孕妇怎么补铁
def retranslateUi(lf, MainWindow):
MainWindow.tWindowTitle(_translate("MainWindow","MainWindow",None))
class DrawChart():
def__init__(lf, code='sz50', start=str(day()- datetime.timedelta(days=200)), end=str(day()+ datetime.timedelta(days =1)), ktype='D'):
lf.start = start
lf.ktype = ktype
lf.data_list, lf.t = lf.getData()
def pyqtgraphDrawChart(lf):
try:
蚂蚁有多少种类>职业体验
lf.item = CandlestickItem(lf.data_list)
lf.xdict ={0:str(lf.hist_data.index[0]).replace('-','/'),int((lf.t +1)/2)-1:str(lf.hist_data.index[int((lf.t +1)/2)]).replace('-','/'), lf.t -1:str (lf.hist_data.index[-1]).replace('-','/')}
lf.stringaxis = pg.AxisItem(orientation='bottom')
lf.stringaxis.tTicks([lf.xdict.items()])
lf.plt = pg.PlotWidget(axisItems={'bottom': lf.stringaxis}, enableMenu=Fal)
lf.plt.addItem(lf.item)
# lf.plt.showGrid(x=True, y=True)
return lf.plt
except:
return pg.PlotWidget()
俊俏def getData(lf):
lf.start =str(day()- datetime.timedelta(days=150))
lf.hist_data = ts.get_hist_de, lf.start, lf.end, lf.ktype).sort_index()[-300:-1]
data_list =[]
t =0
for dates, row in lf.hist_data.iterrows():
什么是留守儿童open, high, clo, low, volume, price_change, p_change, ma5, ma10, ma20 = row[:10]
datas =(t,open, clo, low, high, volume, price_change, p_change, ma5, ma10, ma20)
data_list.append(datas)
t +=1
return data_list, t
class CandlestickItem(pg.GraphicsObject):
def__init__(lf, data):
pg.GraphicsObject.__init__(lf)
lf.data = data
def generatePicture(lf):
lf.picture = QtGui.QPicture()
p = QtGui.QPainter(lf.picture)
p.tPen(pg.mkPen('w'))
w =(lf.data[1][0]- lf.data[0][0])/3.
prema5 =0
prema10 =0
prema20 =0
for(t,open, clo,min,max, volume, price_change, p_change, ma5, ma10, ma20)in lf.data: if open> clo:
p.tPen(pg.mkPen('g'))
p.tBrush(pg.mkBrush('g'))
el:
p.tPen(pg.mkPen('r'))
p.tBrush(pg.mkBrush('r'))
p.drawLine(QtCore.QPointF(t,min), QtCore.QPointF(t,max))
p.drawRect(QtCore.QRectF(t - w,open, w *2, clo -open))
if prema5 !=0:
p.tPen(pg.mkPen('w'))
p.tBrush(pg.mkBrush('w'))
p.drawLine(QtCore.QPointF(t-1, prema5), QtCore.QPointF(t, ma5))
prema5 = ma5
if prema10 !=0:
p.tPen(pg.mkPen('c'))
p.tBrush(pg.mkBrush('c'))
p.drawLine(QtCore.QPointF(t-1, prema10), QtCore.QPointF(t, ma10))
prema10 = ma10
if prema20 !=0:
p.tPen(pg.mkPen('m'))
p.tBrush(pg.mkBrush('m'))
p.drawLine(QtCore.QPointF(t-1, prema20), QtCore.QPointF(t, ma20))
prema20 = ma20
def paint(lf, p,*args):
p.drawPicture(0,0, lf.picture)
def boundingRect(lf):
return QtCore.QRectF(lf.picture.boundingRect())
if __name__ =="__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.tupUi(MainWindow)
MainWindow.show()
<_())

本文发布于:2023-07-20 19:34:44,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1107488.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:种类   股票   中国   补铁   留守   孕妇   儿童   职业
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图