SBGit-2019 / Pyside-QCP

Pyside2 bindings for QCustomplot
Other
17 stars 1 forks source link

Pyside2 bindings for QCustomplot

This project provides Python (v3.6 - v3.10) bindings for the popular OpenSource QCustomPlot (v2.1.0) Qt (v5.15.2) plotting library. The bindings are provided for Linux and Windows (64bit).

The project can be found on Github.

Installation

You can install the library and run the examples with the following commands. Preferably you should do this in a python virtual environment.

pip install qcustomplot_pyside2  # Install latest version of the library
qcustomplot_examples             # Start demos with default delay
qcustomplot_examples 0           # Start demos without automatic continuation
qcustomplot_examples 5000        # Continue demos every 5000 ms

Examples

The folder qcustomplot_examples_pyside2 contains the examples from the QCustomplot C++ webpage translated to Python. These can be used as basis for own development or for seeing the features of the library.

Running all examples

The example command qcustomplot_examples linking to the script all_demos.py runs through all examples with a default or user specified delay time.

Simple example code

import shiboken2 as Shiboken
from PySide2 import QtGui
import sys
import math
from random import uniform,randint
from PySide2.QtWidgets import QApplication, QDialog, QLineEdit, QPushButton, QVBoxLayout,QWidget,QMainWindow
from PySide2.QtGui import QLinearGradient, QRadialGradient, QColor, QBrush, QPen, QFont, QPixmap, QPainterPath
from PySide2.QtCore import Qt, QMargins,QPointF,QObject,QCoreApplication,QFile,QTimer,QLocale,QDateTime,QDate,QSize,QTime
from PySide2.QtUiTools import QUiLoader
from qcustomplot_pyside2 import *

def demo(app):
  # Create plot
  customPlot = QCustomPlot()
  customPlot.resize(800, 600)
  customPlot.setWindowTitle('Quadratic Demo')

  # generate some data:
  x = [0.0] * 101 # initialize with entries 0..100
  y = [0.0] * 101 
  for i in range(0, 101):
    x[i] = i/50.0 - 1 # x goes from -1 to 1
    y[i] = x[i]*x[i]  # let's plot a quadratic function

  # create graph and assign data to it:
  customPlot.addGraph()
  customPlot.graph(0).setData(x, y)
  # give the axes some labels:
  customPlot.xAxis.setLabel("x")
  customPlot.yAxis.setLabel("y")
  # set axes ranges, so we see all data:
  customPlot.xAxis.setRange(-1, 1)
  customPlot.yAxis.setRange(0, 1)

  # show the plot
  customPlot.show()
  # run the main Qt loop
  res = app.exec_()
  # Make sure and manually reset pointer
  customPlot = None
  return res

if __name__ == '__main__':
  # Create the Qt Application
  app = QApplication(sys.argv)
  res = demo(app)
  sys.exit(res)

Screenshots

See the [Wiki] (https://github.com/SBGit-2019/Pyside-QCP/wiki) for some screenshots and explanations. All screenshots can also be found in the figures directory.

Versions

The version naming of the Python bindings is analogue to the naming of the QCustomPlot library.

License

This project is licensed under the GPLv3+ License - see the LICENSE file for details.

Additionally, you can also use these bindings / these python wheels in commercial projects:

Note that commercial licenses are available for [QCustomPlot] at https://www.qcustomplot.com/.

Acknowledgments