gpt4 book ai didi

python - 由于缩放,pyqtgraph中的图像被隐藏

转载 作者:太空宇宙 更新时间:2023-11-03 20:58:01 27 4
gpt4 key购买 nike

我使用 pyqtgraph 来绘制蜡烛,但是如果我将图表放大很多,图像就会隐藏。

我注意到当缩放非常大时,“paint”方法停止被调用。下面带有http请求的代码进行交换。

图像示例

enter image description here

import pyqtgraph as pg
from pyqtgraph import QtCore, QtGui
from PyQt5 import QtWidgets

class CandlestickItem(QtWidgets.QGraphicsRectItem):
def __init__(self, data):
super(CandlestickItem, self).__init__()
self.data = data
self.generatePicture()

def generatePicture(self):
self.picture = QtGui.QPicture()
p = QtGui.QPainter(self.picture)
p.setPen(pg.mkPen('w'))
w = (self.data[1][0] - self.data[0][0]) / 3.
for (t, open, close, min, max) in self.data:
if max != min:
p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max))
if open > close:
p.setBrush(pg.mkBrush('r'))
else:
p.setBrush(pg.mkBrush('g'))
p.drawRect(QtCore.QRectF(t - w, open, w * 2, close - open))
p.end()

def paint(self, p, *args):
print('paint call')
p.drawPicture(0, 0, self.picture)

def boundingRect(self):
return QtCore.QRectF(self.picture.boundingRect())


if __name__ == '__main__':
import sys
import urllib.request
import json

get_symbols_url = 'https://api.hitbtc.com/api/2/public/candles/BCNBTC?period=M30&limit=1000'
response = urllib.request.urlopen(get_symbols_url)
request_data = json.loads(response.read())
data_list = []
for i in range(0, len(request_data)):
data_list.append((float(i), float(request_data[i]['open']), float(request_data[i]['close']),
float(request_data[i]['min']), float(request_data[i]['max'])))

item = CandlestickItem(data_list)
plt = pg.plot()
plt.addItem(item)

if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

我需要显示非常小的值,例如0.0000001-0.00000015。如何防止图像在高变焦时隐藏?

最佳答案

我在支持论坛上得到了答复,它对我有用。 question on forum

这似乎是一个舍入错误。需要替换boundingRect的方法。

    # import numpy as np
def boundingRect(self):
data = np.array(self.data)
xmin = data[:,0].min()
xmax = data[:,0].max()
ymin = data[:,1:].min()
ymax = data[:,1:].max()
return QtCore.QRectF(xmin, ymin, xmax-xmin, ymax-ymin)

关于python - 由于缩放,pyqtgraph中的图像被隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55890900/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com