@@ -0,0 +1,2574 @@
+# -*- coding: utf-8 -*-%0A#%0A# Licensed under the terms of the MIT License%0A# Copyright (c) 2015 Pierre Raybaut%0A%0A# from  https://github.com/PierreRaybaut/plotpy/wiki/Using-Qt-Charts-(PyQtChart)-to-plot-curves-efficiently-in-Python!%0A%0A%0A%22%22%22%0ASimple example illustrating Qt Charts capabilities to plot curves with %0Aa high number of points, using OpenGL accelerated series%0A%22%22%22%0A%0Afrom PyQt5.QtChart import QChart, QChartView, QLineSeries%0Afrom PyQt5.QtGui import QPolygonF, QPainter%0Afrom PyQt5.QtWidgets import QMainWindow%0A%0Aimport numpy as np%0A%0A%0Adef series_to_polyline(xdata, ydata):%0A    %22%22%22Convert series data to QPolygon(F) polyline%0A%0A    This code is derived from PythonQwt's function named %0A    %60qwt.plot_curve.series_to_polyline%60%22%22%22%0A    size = len(xdata)%0A    polyline = QPolygonF(size)%0A    pointer = polyline.data()%0A    dtype, tinfo = np.float, np.finfo  # integers: = np.int, np.iinfo%0A    pointer.setsize(2*polyline.size()*tinfo(dtype).dtype.itemsize)%0A    memory = np.frombuffer(pointer, dtype)%0A    memory%5B:(size-1)*2+1:2%5D = xdata%0A    memory%5B1:(size-1)*2+2:2%5D = ydata%0A    return polyline    %0A%0A%0Aclass TestWindow(QMainWindow):%0A    def __init__(self, parent=None):%0A        super(TestWindow, self).__init__(parent=parent)%0A        self.ncurves = 0%0A        self.chart = QChart()%0A        self.chart.legend().hide()%0A        self.view = QChartView(self.chart)%0A        self.view.setRenderHint(QPainter.Antialiasing)%0A        self.setCentralWidget(self.view)%0A%0A    def set_title(self, title):%0A        self.chart.setTitle(title)%0A%0A    def add_data(self, xdata, ydata, color=None):%0A        curve = QLineSeries()%0A        pen = curve.pen()%0A        if color is not None:%0A            pen.setColor(color)%0A        pen.setWidthF(.1)%0A        curve.setPen(pen)%0A        curve.setUseOpenGL(True)%0A        curve.append(series_to_polyline(xdata, ydata))%0A        self.chart.addSeries(curve)%0A        self.chart.createDefaultAxes()%0A        self.ncurves += 1%0A%0A%0Aif __name__ == '__main__':%0A    import sys%0A    from PyQt5.QtWidgets import QApplication%0A    from PyQt5.QtCore import Qt%0A    app = QApplication(sys.argv)%0A%0A    window = TestWindow()%0A%0A    npoints = 1000000%0A    xdata = np.linspace(0., 10., npoints)%0A    window.add_data(xdata, np.sin(xdata), color=Qt.red)%0A    window.add_data(xdata, np.cos(xdata), color=Qt.blue)%0A    window.set_title(%22Simple example with %25d curves of %25d points %22%5C%0A                     %22(OpenGL Accelerated Series)%22%5C%0A                     %25 (window.ncurves, npoints))%0A    window.setWindowTitle(%22Simple performance example%22)%0A    window.show()%0A    window.resize(500, 400)%0A%0A    sys.exit(app.exec_())%0A

test charts