It works, thank you so much!

понедельник, 29 апреля 2019 г., 7:55:49 UTC+3 пользователь Patrick написал:
>
> Hi,
>
> I don't know exactly why that would be happening, but seems like a 
> rounding error somewhere. Your bounding box function is returning a y-axis 
> range of 0 to 1 (which I assume is from the minimum size of the picture 
> object maybe?) even though the data is a million times smaller than that.
>
> If I change the bounding box method to:
>     # 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)
> then it seems to work better.
>
> Also needed to change this for python3:
> request_data = json.loads(data.decode('utf8'))
>
> Patrick
>
> On Monday, 29 April 2019 04:23:40 UTC+9:30, [email protected] wrote:
>>
>> I use pyqtgraph to draw the candles, but if I zoom graph very much, image 
>> hide.
>>
>> I noticed that when zoom very much, “paint” method stops being called. 
>> Code with http request to exchange below.
>>
>> import pyqtgraph as pgfrom pyqtgraph import QtCore, QtGuifrom 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_()
>>
>> I need to display very small values, for example, 0.0000001-0.00000015. 
>> What can I do to prevent image hidden at high zoom?
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/8dd12f28-ccba-4db0-926a-35c79bce50ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to