Interactive plotting widgets — PlotPy 2.7 Manual (original) (raw)
Overview¶
The pyplot module provides an interactive plotting interface similar toMatplotlib’s, i.e. with MATLAB-like syntax.
The 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 plotpy does support the plotting commands called in your script, replacingimport matplotlib.pyplot
by import plotpy.pyplot
should be enough, 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 plotpy is trivial:
import plotpy.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 import plotpy.pyplot as plt plt.ion() # switching to interactive mode x = np.linspace(-5, 5, 1000) plt.figure(1) plt.subplot(2, 1, 1) plt.plot(x, np.sin(x), "r+") plt.plot(x, np.cos(x), "g-") plt.errorbar(x, -1+x*2/20+.2np.random.rand(len(x)), x/20) plt.xlabel("Axe x") plt.ylabel("Axe y") plt.subplot(2, 1, 2) img = np.fromfunction(lambda x, y: np.sin((x/200.)*(y/200.)**2), (1000, 1000)) plt.xlabel("pixels") plt.ylabel("pixels") plt.zlabel("intensity") plt.gray() plt.imshow(img) plt.figure("plotyy") plt.plotyy(x, np.sin(x), x, np.cos(x)) plt.ylabel("sinus", "cosinus") plt.show()
Reference¶
plotpy.pyplot.interactive(state)[source]¶
Toggle interactive mode
Turn interactive mode on
Turn interactive mode off
plotpy.pyplot.figure(N=None)[source]¶
Create a new figure
Get current figure
Get current axes
plotpy.pyplot.show(mainloop=True)[source]¶
Show all figures and enter Qt event loop This should be the last line of your script
plotpy.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()
plotpy.pyplot.close(N=None, all=False)[source]¶
Close figure
plotpy.pyplot.title(text)[source]¶
Set current figure title
plotpy.pyplot.xlabel(bottom='', top='')[source]¶
Set current x-axis label
plotpy.pyplot.ylabel(left='', right='')[source]¶
Set current y-axis label
plotpy.pyplot.zlabel(label)[source]¶
Set current z-axis label
plotpy.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
plotpy.pyplot.grid(act)[source]¶
Toggle grid visibility
plotpy.pyplot.legend(pos='TR')[source]¶
Add legend to current axes (pos=’TR’, ‘TL’, ‘BR’, …)
plotpy.pyplot.colormap(name)[source]¶
Set color map to name
plotpy.pyplot.savefig(fname, format=None)[source]¶
Save figure
Currently supports QImageWriter formats only (see https://doc.qt.io/qt-5/qimagewriter.html#supportedImageFormats)
plotpy.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()
plotpy.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()
plotpy.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()
plotpy.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()
plotpy.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()
plotpy.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+.2np.random.rand(len(x)), x/20) show()
plotpy.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()
plotpy.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()
plotpy.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 = Rnp.cos(TH) Y = Rnp.sin(TH) Z = 4*TH+R pcolor(X, Y, Z) show()