guiqwt.pyplot

The pyplot module provides an interactive plotting interface similar to Matplotlib’s, i.e. with MATLAB-like syntax.

The guiqwt.pyplot module was designed to be as close as possible to the matplotlib.pyplot module, so that one could easily switch between these two modules by simply changing the import statement. Basically, if guiqwt does support the plotting commands called in your script, replacing import matplotlib.pyplot by import guiqwt.pyplot should suffice, as shown in the following example:

  • Simple example using matplotlib:

    import matplotlib.pyplot as plt
    import numpy as np
    x = np.linspace(-10, 10)
    plt.plot(x, x**2, 'r+')
    plt.show()
    
  • Switching from matplotlib to guiqwt is trivial:

    import guiqwt.pyplot as plt # only this line has changed!
    import numpy as np
    x = np.linspace(-10, 10)
    plt.plot(x, x**2, 'r+')
    plt.show()
    

Examples

>>> import numpy as np
>>> from guiqwt.pyplot import * # ugly but acceptable in an interactive session
>>> ion() # switching to interactive mode
>>> x = np.linspace(-5, 5, 1000)
>>> figure(1)
>>> subplot(2, 1, 1)
>>> plot(x, np.sin(x), "r+")
>>> plot(x, np.cos(x), "g-")
>>> errorbar(x, -1+x**2/20+.2*np.random.rand(len(x)), x/20)
>>> xlabel("Axe x")
>>> ylabel("Axe y")
>>> subplot(2, 1, 2)
>>> img = np.fromfunction(lambda x, y: np.sin((x/200.)*(y/200.)**2), (1000, 1000))
>>> xlabel("pixels")
>>> ylabel("pixels")
>>> zlabel("intensity")
>>> gray()
>>> imshow(img)
>>> figure("plotyy")
>>> plotyy(x, np.sin(x), x, np.cos(x))
>>> ylabel("sinus", "cosinus")
>>> show()

Reference

guiqwt.pyplot.interactive(state)[source]

Toggle interactive mode

guiqwt.pyplot.ion()[source]

Turn interactive mode on

guiqwt.pyplot.ioff()[source]

Turn interactive mode off

guiqwt.pyplot.figure(N=None)[source]

Create a new figure

guiqwt.pyplot.gcf()[source]

Get current figure

guiqwt.pyplot.gca()[source]

Get current axes

guiqwt.pyplot.show(mainloop=True)[source]

Show all figures and enter Qt event loop This should be the last line of your script

guiqwt.pyplot.subplot(n, m, k)[source]

Create a subplot command

Example:

import numpy as np
x = np.linspace(-5, 5, 1000)
figure(1)
subplot(2, 1, 1)
plot(x, np.sin(x), "r+")
subplot(2, 1, 2)
plot(x, np.cos(x), "g-")
show()
guiqwt.pyplot.close(N=None, all=False)[source]

Close figure

guiqwt.pyplot.title(text)[source]

Set current figure title

guiqwt.pyplot.xlabel(bottom='', top='')[source]

Set current x-axis label

guiqwt.pyplot.ylabel(left='', right='')[source]

Set current y-axis label

guiqwt.pyplot.zlabel(label)[source]

Set current z-axis label

guiqwt.pyplot.yreverse(reverse)[source]

Set y-axis direction of increasing values

reverse = False (default)

y-axis values increase from bottom to top

reverse = True

y-axis values increase from top to bottom

guiqwt.pyplot.grid(act)[source]

Toggle grid visibility

guiqwt.pyplot.legend(pos='TR')[source]

Add legend to current axes (pos=’TR’, ‘TL’, ‘BR’, …)

guiqwt.pyplot.colormap(name)[source]

Set color map to name

guiqwt.pyplot.savefig(fname, format=None)[source]

Save figure

Currently supports QImageWriter formats only (see https://doc.qt.io/qt-5/qimagewriter.html#supportedImageFormats)

guiqwt.pyplot.plot(*args, **kwargs)[source]

Plot curves

Example:

import numpy as np
x = np.linspace(-5, 5, 1000)
plot(x, np.sin(x), "r+")
plot(x, np.cos(x), "g-")
show()
guiqwt.pyplot.plotyy(x1, y1, x2, y2)[source]

Plot curves with two different y axes

Example:

import numpy as np
x = np.linspace(-5, 5, 1000)
plotyy(x, np.sin(x), x, np.cos(x))
ylabel("sinus", "cosinus")
show()
guiqwt.pyplot.semilogx(*args, **kwargs)[source]

Plot curves with logarithmic x-axis scale

Example:

import numpy as np
x = np.linspace(-5, 5, 1000)
semilogx(x, np.sin(12*x), "g-")
show()
guiqwt.pyplot.semilogy(*args, **kwargs)[source]

Plot curves with logarithmic y-axis scale

Example:

import numpy as np
x = np.linspace(-5, 5, 1000)
semilogy(x, np.sin(12*x), "g-")
show()
guiqwt.pyplot.loglog(*args, **kwargs)[source]

Plot curves with logarithmic x-axis and y-axis scales

Example:

import numpy as np
x = np.linspace(-5, 5, 1000)
loglog(x, np.sin(12*x), "g-")
show()
guiqwt.pyplot.errorbar(*args, **kwargs)[source]

Plot curves with error bars

Example:

import numpy as np
x = np.linspace(-5, 5, 1000)
errorbar(x, -1+x**2/20+.2*np.random.rand(len(x)), x/20)
show()
guiqwt.pyplot.hist(data, bins=None, logscale=None, title=None, color=None)[source]

Plot 1-D histogram

Example:

from numpy.random import normal
data = normal(0, 1, (2000, ))
hist(data)
show()
guiqwt.pyplot.imshow(data, interpolation=None, mask=None)[source]

Display the image in data to current axes interpolation: ‘nearest’, ‘linear’ (default), ‘antialiasing’

Example:

import numpy as np
x = np.linspace(-5, 5, 1000)
img = np.fromfunction(lambda x, y: np.sin((x/200.)*(y/200.)**2), (1000, 1000))
gray()
imshow(img)
show()
guiqwt.pyplot.pcolor(*args)[source]

Create a pseudocolor plot of a 2-D array

Example:

import numpy as np
r = np.linspace(1., 16, 100)
th = np.linspace(0., np.pi, 100)
R, TH = np.meshgrid(r, th)
X = R*np.cos(TH)
Y = R*np.sin(TH)
Z = 4*TH+R
pcolor(X, Y, Z)
show()