mpl.pyplot

Provides a MATLAB-like plotting framework.

pylab combines pyplot with numpy into a single namespace. This is convenient for interactive work, but for programming it is recommended that the namespaces be kept separate, e.g.:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)

Functions

acorr(x[, hold, data]) Plot the autocorrelation of x.
angle_spectrum(x[, Fs, Fc, window, pad_to, ...]) Plot the angle spectrum.
annotate(*args, **kwargs) Create an annotation: a piece of text referring to a data point.
arrow(x, y, dx, dy[, hold]) Add an arrow to the axes.
autoscale([enable, axis, tight]) Autoscale the axis view to the data (toggle).
autumn() set the default colormap to autumn and apply to current image if any.
axes(*args, **kwargs) Add an axes to the figure.
axhline([y, xmin, xmax, hold]) Add a horizontal line across the axis.
axhspan(ymin, ymax[, xmin, xmax, hold]) Add a horizontal span (rectangle) across the axis.
axis(*v, **kwargs) Convenience method to get or set axis properties.
axvline([x, ymin, ymax, hold]) Add a vertical line across the axes.
axvspan(xmin, xmax[, ymin, ymax, hold]) Add a vertical span (rectangle) across the axes.
bar(left, height[, width, bottom, hold, data]) Make a bar plot.
barbs(*args, **kw) Plot a 2-D field of barbs.
barh(bottom, width[, height, left, hold]) Make a horizontal bar plot.
bone() set the default colormap to bone and apply to current image if any.
box([on]) Turn the axes box on or off.
boxplot(x[, notch, sym, vert, whis, ...]) Make a box and whisker plot.
broken_barh(xranges, yrange[, hold, data]) Plot horizontal bars.
cla() Clear the current axes.
clabel(CS, *args, **kwargs) Label a contour plot.
clf() Clear the current figure.
clim([vmin, vmax]) Set the color limits of the current image.
close(*args) Close a figure window.
cohere(x, y[, NFFT, Fs, Fc, detrend, ...]) Plot the coherence between x and y.
colorbar([mappable, cax, ax]) Add a colorbar to a plot.
colormaps() Matplotlib provides a number of colormaps, and others can be added using register_cmap().
colors() This is a do-nothing function to provide you with help on how matplotlib handles colors.
connect(s, func) Connect event with string s to func.
contour(*args, **kwargs) Plot contours.
contourf(*args, **kwargs) Plot contours.
cool() set the default colormap to cool and apply to current image if any.
copper() set the default colormap to copper and apply to current image if any.
csd(x, y[, NFFT, Fs, Fc, detrend, window, ...]) Plot the cross-spectral density.
cycler(*args, **kwargs) Create a new Cycler object from a single positional argument, a pair of positional arguments, or the combination of keyword arguments.
dedent(s) Remove excess indentation from docstring s.
delaxes(*args) Remove an axes from the current figure.
disconnect(cid) Disconnect callback id cid
draw() Redraw the current figure.
draw_if_interactive() Is called after every pylab drawing command
errorbar(x, y[, yerr, xerr, fmt, ecolor, ...]) Plot an errorbar graph.
eventplot(positions[, orientation, ...]) Plot identical parallel lines at specific positions.
figaspect(arg) Create a figure with specified aspect ratio.
figimage(*args, **kwargs) Adds a non-resampled image to the figure.
figlegend(handles, labels, loc, **kwargs) Place a legend in the figure.
fignum_exists(num)
figtext(*args, **kwargs) Add text to figure.
figure([num, figsize, dpi, facecolor, ...]) Creates a new figure.
fill(*args, **kwargs) Plot filled polygons.
fill_between(x, y1[, y2, where, ...]) Make filled polygons between two curves.
fill_betweenx(y, x1[, x2, where, step, ...]) Make filled polygons between two horizontal curves.
findobj([o, match, include_self]) Find artist objects.
flag() set the default colormap to flag and apply to current image if any.
gca(**kwargs) Get the current Axes instance on the current figure matching the given keyword args, or create one.
gcf() Get a reference to the current figure.
gci() Get the current colorable artist.
get(obj[, property]) Return the value of object’s property.
get_backend() Return the name of the current backend.
get_cmap([name, lut]) Get a colormap instance, defaulting to rc values if name is None.
get_current_fig_manager()
get_figlabels() Return a list of existing figure labels.
get_fignums() Return a list of existing figure numbers.
get_plot_commands() Get a sorted list of all of the plotting commands.
get_scale_docs() Helper function for generating docstrings related to scales.
get_scale_names()
getp(obj[, property]) Return the value of object’s property.
ginput(*args, **kwargs) Call signature:
gray() set the default colormap to gray and apply to current image if any.
grid([b, which, axis]) Turn the axes grids on or off.
hexbin(x, y[, C, gridsize, bins, xscale, ...]) Make a hexagonal binning plot.
hist(x[, bins, range, normed, weights, ...]) Plot a histogram.
hist2d(x, y[, bins, range, normed, weights, ...]) Make a 2D histogram plot.
hlines(y, xmin, xmax[, colors, linestyles, ...]) Plot horizontal lines at each y from xmin to xmax.
hold([b]) Set the hold state.
hot() set the default colormap to hot and apply to current image if any.
hsv() set the default colormap to hsv and apply to current image if any.
imread(*args, **kwargs) Read an image from a file into an array.
imsave(*args, **kwargs) Save an array as in image file.
imshow(X[, cmap, norm, aspect, ...]) Display an image on the axes.
inferno() set the default colormap to inferno and apply to current image if any.
install_repl_displayhook() Install a repl display hook so that any stale figure are automatically redrawn when control is returned to the repl.
interactive(b) Set interactive mode to boolean b.
ioff() Turn interactive mode off.
ion() Turn interactive mode on.
is_numlike(obj) return true if obj looks like a number
is_string_like(obj) Return True if obj looks like a string
ishold() Return the hold status of the current axes.
isinteractive() Return status of interactive mode.
jet() set the default colormap to jet and apply to current image if any.
legend(*args, **kwargs) Places a legend on the axes.
locator_params([axis, tight]) Control behavior of tick locators.
loglog(*args, **kwargs) Make a plot with log scaling on both the x and y axis.
magma() set the default colormap to magma and apply to current image if any.
magnitude_spectrum(x[, Fs, Fc, window, ...]) Plot the magnitude spectrum.
margins(*args, **kw) Set or retrieve autoscaling margins.
matshow(A[, fignum]) Display an array as a matrix in a new figure window.
minorticks_off() Remove minor ticks from the current plot.
minorticks_on() Display minor ticks on the current plot.
new_figure_manager(num, *args, **kwargs) Create a new figure manager instance
over(func, *args, **kwargs) Call a function with hold(True).
pause(interval) Pause for interval seconds.
pcolor(*args, **kwargs) Create a pseudocolor plot of a 2-D array.
pcolormesh(*args, **kwargs) Plot a quadrilateral mesh.
phase_spectrum(x[, Fs, Fc, window, pad_to, ...]) Plot the phase spectrum.
pie(x[, explode, labels, colors, autopct, ...]) Plot a pie chart.
pink() set the default colormap to pink and apply to current image if any.
plasma() set the default colormap to plasma and apply to current image if any.
plot(*args, **kwargs) Plot lines and/or markers to the Axes.
plot_date(x, y[, fmt, tz, xdate, ydate, ...]) Plot with data with dates.
plotfile(fname[, cols, plotfuncs, comments, ...]) Plot the data in in a file.
plotting()
polar(*args, **kwargs) Make a polar plot.
prism() set the default colormap to prism and apply to current image if any.
psd(x[, NFFT, Fs, Fc, detrend, window, ...]) Plot the power spectral density.
pylab_setup() return new_figure_manager, draw_if_interactive and show for pylab
quiver(*args, **kw) Plot a 2-D field of arrows.
quiverkey(*args, **kw) Add a key to a quiver plot.
rc(*args, **kwargs) Set the current rc params.
rc_context([rc, fname]) Return a context manager for managing rc settings.
rcdefaults() Restore the default rc params.
register_cmap([name, cmap, data, lut]) Add a colormap to the set recognized by get_cmap().
rgrids(*args, **kwargs) Get or set the radial gridlines on a polar plot.
savefig(*args, **kwargs) Save the current figure.
sca(ax) Set the current Axes instance to ax.
scatter(x, y[, s, c, marker, cmap, norm, ...]) Make a scatter plot of x vs y, where x and y are sequence like objects of the same lengths.
sci(im) Set the current image.
semilogx(*args, **kwargs) Make a plot with log scaling on the x axis.
semilogy(*args, **kwargs) Make a plot with log scaling on the y axis.
set_cmap(cmap) Set the default colormap.
setp(*args, **kwargs) Set a property on an artist object.
show(*args, **kw) Display a figure.
specgram(x[, NFFT, Fs, Fc, detrend, window, ...]) Plot a spectrogram.
spectral() set the default colormap to spectral and apply to current image if any.
spring() set the default colormap to spring and apply to current image if any.
spy(Z[, precision, marker, markersize, ...]) Plot the sparsity pattern on a 2-D array.
stackplot(x, *args, **kwargs) Draws a stacked area plot.
stem(*args, **kwargs) Create a stem plot.
step(x, y, *args, **kwargs) Make a step plot.
streamplot(x, y, u, v[, density, linewidth, ...]) Draws streamlines of a vector flow.
subplot(*args, **kwargs) Return a subplot axes positioned by the given grid definition.
subplot2grid(shape, loc[, rowspan, colspan]) Create a subplot in a grid.
subplot_tool([targetfig]) Launch a subplot tool window for a figure.
subplots([nrows, ncols, sharex, sharey, ...]) Create a figure with a set of subplots already made.
subplots_adjust(*args, **kwargs) Tune the subplot layout.
summer() set the default colormap to summer and apply to current image if any.
suptitle(*args, **kwargs) Add a centered title to the figure.
switch_backend(newbackend) Switch the default backend.
table(**kwargs) Add a table to the current axes.
text(x, y, s[, fontdict, withdash]) Add text to the axes.
thetagrids(*args, **kwargs) Get or set the theta locations of the gridlines in a polar plot.
tick_params([axis]) Change the appearance of ticks and tick labels.
ticklabel_format(**kwargs) Change the ~matplotlib.ticker.ScalarFormatter used by default for linear axes.
tight_layout([pad, h_pad, w_pad, rect]) Automatically adjust subplot parameters to give specified padding.
title(s, *args, **kwargs) Set a title of the current axes.
tricontour(*args, **kwargs) Draw contours on an unstructured triangular grid.
tricontourf(*args, **kwargs) Draw contours on an unstructured triangular grid.
tripcolor(*args, **kwargs) Create a pseudocolor plot of an unstructured triangular grid.
triplot(*args, **kwargs) Draw a unstructured triangular grid as lines and/or markers.
twinx([ax]) Make a second axes that shares the x-axis.
twiny([ax]) Make a second axes that shares the y-axis.
uninstall_repl_displayhook() Uninstalls the matplotlib display hook.
violinplot(dataset[, positions, vert, ...]) Make a violin plot.
viridis() set the default colormap to viridis and apply to current image if any.
vlines(x, ymin, ymax[, colors, linestyles, ...]) Plot vertical lines.
waitforbuttonpress(*args, **kwargs) Call signature:
winter() set the default colormap to winter and apply to current image if any.
xcorr(x, y[, normed, detrend, usevlines, ...]) Plot the cross correlation between x and y.
xkcd([scale, length, randomness]) Turns on xkcd sketch-style drawing mode.
xlabel(s, *args, **kwargs) Set the x axis label of the current axis.
xlim(*args, **kwargs) Get or set the x limits of the current axes.
xscale(*args, **kwargs) Set the scaling of the x-axis.
xticks(*args, **kwargs) Get or set the x-limits of the current tick locations and labels.
ylabel(s, *args, **kwargs) Set the y axis label of the current axis.
ylim(*args, **kwargs) Get or set the y-limits of the current axes.
yscale(*args, **kwargs) Set the scaling of the y-axis.
yticks(*args, **kwargs) Get or set the y-limits of the current tick locations and labels.

Classes

Annotation(s, xy[, xytext, xycoords, ...]) A Text class to make annotating things in the figure, such as Figure, Axes, Rectangle, etc., easier.
Arrow(x, y, dx, dy[, width]) An arrow patch.
Artist() Abstract base class for someone who renders into a FigureCanvas.
AutoLocator()
Axes(fig, rect[, axisbg, frameon, sharex, ...]) The Axes contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system.
Button(ax, label[, image, color, hovercolor]) A GUI neutral button.
Circle(xy[, radius]) A circle patch.
Figure([figsize, dpi, facecolor, edgecolor, ...]) The Figure instance supports callbacks through a callbacks attribute which is a matplotlib.cbook.CallbackRegistry instance.
FigureCanvasBase(figure) The canvas the figure renders into.
FixedFormatter(seq) Return fixed strings for tick labels
FixedLocator(locs[, nbins]) Tick locations are fixed.
FormatStrFormatter(fmt) Use an old-style (‘%’ operator) format string to format the tick
Formatter Convert the tick location to a string
FuncFormatter(func) User defined function for formatting
GridSpec(nrows, ncols[, left, bottom, ...]) A class that specifies the geometry of the grid that a subplot will be placed.
IndexLocator(base, offset) Place a tick on every multiple of some base number of points plotted, e.g., on every 5th point.
Line2D(xdata, ydata[, linewidth, linestyle, ...]) A line - the line can have both a solid linestyle connecting all the vertices, and a marker at each vertex.
LinearLocator([numticks, presets]) Determine the tick locations
Locator Determine the tick locations;
LogFormatter([base, labelOnlyBase]) Format values for log axis;
LogFormatterExponent([base, labelOnlyBase]) Format values for log axis; using exponent = log_base(value)
LogFormatterMathtext([base, labelOnlyBase]) Format values for log axis; using exponent = log_base(value)
LogLocator([base, subs, numdecs, numticks]) Determine the tick locations for log axes
MaxNLocator(*args, **kwargs) Select no more than N intervals at nice locations.
MultipleLocator([base]) Set a tick on every integer that is multiple of base in the
Normalize([vmin, vmax, clip]) A class which, when called, can normalize data into the [0.0, 1.0] interval.
NullFormatter Always return the empty string
NullLocator No ticks
PolarAxes(*args, **kwargs) A polar graph projection, where the input dimensions are theta, r.
Polygon(xy[, closed]) A general polygon patch.
Rectangle(xy, width, height[, angle]) Draw a rectangle with lower left at xy = (x, y) with specified width and height.
ScalarFormatter([useOffset, useMathText, ...]) Tick location is a plain old number.
Slider(ax, label, valmin, valmax[, valinit, ...]) A slider representing a floating point range.
Subplot alias of AxesSubplot
SubplotTool(targetfig, toolfig) A tool to adjust the subplot params of a matplotlib.figure.Figure.
Text([x, y, text, color, verticalalignment, ...]) Handle storing and drawing of text in window or data coordinates.
TickHelper
Widget Abstract base class for GUI neutral widgets
silent_list(type[, seq]) override repr when returning a list of matplotlib artists to