Support This Project

PyQwt Command Line Interpreter Examples

The programming style imposed by PyQt (and other GUI toolkit wrappers) is to create an application instance with some widgets and to enter into an event loop that locks you from the Python command line interpreter or an enhanced interpreter like IPython.

PyQwt includes the iqt module that allows to:

  • create and control (Py)Qt widgets from the command line interpreter.
  • interact with those widgets through (Py)Qt's GUI.

Note: on Windows, the iqt module requires at least PyQwt-5.0.1 or PyQwt-4.2.3.

A step by step example follows:

  1. Start python (or ipython) and type:
    >>> import numpy as np
    to import numpy while giving it a short name.
  2. The module PyQt4.Qwt5.iqt makes it possible to combine the read-eval-print loop of the Python interpreter with the event loop of Qt. Type:
    >>> import PyQt4.Qwt5.iqt
    to create an application instance and to simulate entering an event loop which does not inhibit the Python interpreter to read its input.
  3. The module qwt.qplt provides an interpreter friendly interface to the QwtPlot class. Type:
    >>> from PyQt4.Qwt5.qplt import *
    to load the classes Plot, IPlot, Curve, Axis, Pen and Symbol.
  4. Type:
    >>> x = np.arange(-2*np.pi, 2*np.pi, 0.01)
    to create an array of x-values, ranging from -2*pi to 2*pi with a step size of 0.01.
  5. Type:
    >>> p = Plot(Curve(x, np.cos(x), Pen(Magenta, 2), "cos(x)"),
    ...          Curve(x, np.exp(x), Pen(Red), "exp(x)", Y2),
    ...          Axis(Right, Log),
    ...          "PyQwt using Qwt-%s --" % QWT_VERSION_STR)
    to show a plot with two curves, a linear x-axis, a linear y-axis, a logarithmic y-axis and a title.

    plot with two curves

    A Plot widget has hidden features:
    • toggle the visibility of each curve by clicking on its legend item.
    • zooming and unzooming uses an infinite deep stack:
      • left-click&drag&release to zoom
      • right-click to unzoom to the previous zoom selection
      • middle-click to unzoom to the initial state
  6. There is also an IPlot widget that adds a few interactive buttons to Plot to facilitate printing to a printer or an (E)PS file and to clone the plot into Grace. Grace is an interactive plotting program producing hardcopy output that is better suited for LaTeX documents and scientific journals. Type:
    >>> p = IPlot(Curve(x, np.cos(x), Pen(Magenta, 2), "cos(x)"),
    ...           Curve(x, np.exp(x), Pen(Red), "exp(x)", Y2),
    ...           Axis(Right, Log),
    ...           "PyQwt using Qwt-%s --" % QWT_VERSION_STR)
    to show it.
  7. Type:
    >>> x = x[0:-1:10]
    to create a new array of x-values by selecting every 10th element of the old array.
  8. Type:
    >>> p.plot(Curve(x, np.cos(x-np.pi/4), Symbol(Circle, Yellow), "circle"),
    ...        Curve(x, np.cos(x+np.pi/4), Pen(Blue), Symbol(Square, Cyan), "square"))
    to add two more curves to the plot.

    plot with four curves

See the PyQt4.Qwt5.qplt documentation for detailed information.

Help to stop software patents

Free software and small and/or medium sized software companies are threatened by patents on algorithms and business methods.

  1. Read this excellent explanation of the devastating effects of software patents on software (users!) and software development (developers!)
  2. Read how the European Commission and the patent lobby are still trying to introduce software patents
  3. Support the Patent Busting Project of the Electronic Frontier Foundation in the USA