def drawSteps(self, painter, xMap, yMap, canvasRect, from_, to): """ Draw steps :param QPainter painter: Painter :param qwt.scale_map.QwtScaleMap xMap: Maps x-values into pixel coordinates. :param qwt.scale_map.QwtScaleMap yMap: Maps y-values into pixel coordinates. :param QRectF canvasRect: Contents rectangle of the canvas :param int from_: Index of the first point to be painted :param int to: Index of the last point to be painted. If to < 0 the curve will be painted to its last point. .. seealso:: :py:meth:`draw()`, :py:meth:`drawSticks()`, :py:meth:`drawDots()`, :py:meth:`drawLines()` """ size = 2 * (to - from_) + 1 if QT_API == "pyside6": polygon = QPolygonF() polygon.resize(size) elif QT_API == "pyqt6": polygon = QPolygonF([QPointF(0, 0)] * size) else: polygon = QPolygonF(size) inverted = self.orientation() == Qt.Vertical if self.__data.attributes & self.Inverted: inverted = not inverted series = self.data() ip = 0 for i in range(from_, to + 1): sample = series.sample(i) xi = xMap.transform(sample.x()) yi = yMap.transform(sample.y()) if ip > 0: p0 = polygon[ip - 2] if inverted: polygon[ip - 1] = QPointF(p0.x(), yi) else: polygon[ip - 1] = QPointF(xi, p0.y()) polygon[ip] = QPointF(xi, yi) ip += 2 painter.drawPolyline(polygon) if self.__data.brush.style() != Qt.NoBrush: self.fillCurve(painter, xMap, yMap, canvasRect, polygon)
def array2d_to_qpolygonf(xdata, ydata): """ Utility function to convert two 1D-NumPy arrays representing curve data (X-axis, Y-axis data) into a single polyline (QtGui.PolygonF object). This feature is compatible with PyQt4, PyQt5 and PySide2 (requires QtPy). License/copyright: MIT License © Pierre Raybaut 2020-2021. :param numpy.ndarray xdata: 1D-NumPy array :param numpy.ndarray ydata: 1D-NumPy array :return: Polyline :rtype: QtGui.QPolygonF """ if not (xdata.size == ydata.size == xdata.shape[0] == ydata.shape[0]): raise ValueError("Arguments must be 1D NumPy arrays with same size") size = xdata.size if QT_API.startswith("pyside"): # PySide (obviously...) if QT_API == "pyside2": polyline = QPolygonF(size) else: polyline = QPolygonF() polyline.resize(size) address = shiboken.getCppPointer(polyline.data())[0] buffer = (ctypes.c_double * 2 * size).from_address(address) else: # PyQt4, PyQt5 if QT_API == "pyqt6": polyline = QPolygonF([QPointF(0, 0)] * size) else: polyline = QPolygonF(size) buffer = polyline.data() buffer.setsize( 16 * size) # 16 bytes per point: 8 bytes per X,Y value (float64) memory = np.frombuffer(buffer, np.float64) memory[:(size - 1) * 2 + 1:2] = np.array(xdata, dtype=np.float64, copy=False) memory[1:(size - 1) * 2 + 2:2] = np.array(ydata, dtype=np.float64, copy=False) return polyline