#Setting up the main plot
self.plot.xAxis.setRange(0, max_date)
self.plot.yAxis.setRange(max_low, max_high)
self.candlesticks = QCPFinancial(self.plot.xAxis, self.plot.yAxis)
#Setting up the sub plot
rect = QCPAxisRect(self.plot)
x_axis = rect.axis(QCPAxis.atBottom)
x_axis.setRange(min_date, max_date) # a portion of the main plot
self.candlesticks2 = QCPFinancial(x_axis, y_axis)
self.plot.plotLayout().addElement(2, 0, self.candlesticks2)
def vline(self, data: QCPFinancialData):
line = QCPItemStraightLine(self.plot)
line.setPen(QPen(Qt.blue))
line.point1.setCoords(data.key, data.close)
line.point2.setCoords(data.key, data.close + 1)
line2 = QCPItemStraightLine(self.plot)
line2.setClipAxisRect(self.candlesticks2)
line2.setPen(QPen(Qt.blue))
line2.point1.setCoords(data.key, data.close)
line2.point2.setCoords(data.key, data.close + 1)
self.plot.replot()
The range of the sub plot is included in the main plot x-axis range. When I draw a line using data.key value, line1 is drawn in the exact position, but line2's pixel coordinate of x is plotted at the same position as the pixel coordinate of the main plot's x. Can you please help me identify the issue?