我想同时从2个绘图中获取数据,所以我需要同步2个绘图x轴。但是,它是2个绘图x轴之间的低容差。我尝试使用System.out.print("The missing number is "+(total-sum));
和setLimits
进行改进,但似乎没有任何帮助。我用得对吗?
由于代码太长,以下是代码的一部分:
setXRange
时间轴轴:
class CandlestickItem(pg.GraphicsObject):
def __init__(self, data):
pg.GraphicsObject.__init__(self)
self.data = data ## data must have fields: time, open, close, min, max
self.generatePicture()
def generatePicture(self):
## pre-computing a QPicture object allows paint() to run much more quickly,
## rather than re-drawing the shapes every time.
self.picture = QtGui.QPicture()
p = QtGui.QPainter(self.picture)
p.setPen(pg.mkPen('k'))
# w = (self.data[1][0] - self.data[0][0]) / 3.
w = 1 / 3.
index = 0
for (t, close, max, min, open) in self.data:
if open > close:
p.setBrush(pg.mkBrush('r'))
p.setPen(pg.mkPen('r'))
else:
p.setBrush(pg.mkBrush('g'))
p.setPen(pg.mkPen('g'))
p.drawLine(QtCore.QPointF(index, min), QtCore.QPointF(index, max))
p.drawRect(QtCore.QRectF(index-w, open, w*2, close-open))
index = index + 1
p.end()
def paint(self, p, *args):
p.drawPicture(0, 0, self.picture)
def boundingRect(self):
## boundingRect _must_ indicate the entire area that will be drawn on
## or else we will get artifacts and possibly crashing.
## (in this case, QPicture does all the work of computing the bouning rect for us)
return QtCore.QRectF(self.picture.boundingRect())
情节图:
class TimeAxisItem(pg.AxisItem):
def __init__(self, xdict, *args, **kwargs):
pg.AxisItem.__init__(self, *args, **kwargs)
# self.x_values = np.asarray(xdict.keys())
self.x_values = list(xdict.keys())
self.x_strings = list(xdict.values())
def tickStrings(self, values, scale, spacing):
strings = []
for v in values:
# vs is the original tick value
vs = int(v * scale)
# if we have vs in our values, show the string
# otherwise show nothing
if vs in self.x_values:
vstr = datetime.fromtimestamp(self.x_strings[vs]).strftime("%Y-%m-%d")
else:
vstr = ""
strings.append(vstr)
return strings