Version 2.2.2
Fork me on GitHub

Table Of Contents


matplotlib.pyplot is a state-based interface to matplotlib. It provides a MATLAB-like way of plotting.

pyplot is mainly intended for interactive plots and simple cases of programmatic plot generation:

import numpy as np
import matplotlib.pyplot as plt

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

The object-oriented API is recommended for more complex plots.


acorr(x[, hold, data]) Plot the autocorrelation of x.
angle_spectrum(x[, Fs, Fc, window, pad_to, …]) Plot the angle spectrum.
annotate(*args, **kwargs) Annotate the point xy with text s.
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 colormap to “autumn”.
axes([arg]) Add an axes to the current figure and make it the current axes.
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(*args, **kwargs) Make a bar plot.
barbs(*args, **kw) Plot a 2-D field of barbs.
barh(*args, **kwargs) Make a horizontal bar plot.
bone() Set the colormap to “bone”.
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 a horizontal sequence of rectangles.
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.
colors() .
connect(s, func) Connect event with string s to func.
contour(*args, **kwargs) Plot contours.
contourf(*args, **kwargs) Plot contours.
cool() Set the colormap to “cool”.
copper() Set the colormap to “copper”.
csd(x, y[, NFFT, Fs, Fc, detrend, window, …]) Plot the cross-spectral density.
delaxes([ax]) Remove the given Axes ax from the current figure.
disconnect(cid) Disconnect callback id cid
draw() Redraw the current figure.
errorbar(x, y[, yerr, xerr, fmt, ecolor, …]) Plot y versus x as lines and/or markers with attached errorbars.
eventplot(positions[, orientation, …]) Plot identical parallel lines at the given positions.
figimage(*args, **kwargs) Adds a non-resampled image to the figure.
figlegend(*args, **kwargs) Place a legend in the figure.
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, …]) Fill the area between two horizontal curves.
fill_betweenx(y, x1[, x2, where, step, …]) Fill the area between two vertical curves.
findobj([o, match, include_self]) Find artist objects.
flag() Set the colormap to “flag”.
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_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.
ginput(*args, **kwargs) Blocking call to interact with a figure.
gray() Set the colormap to “gray”.
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, density, 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]) .
hot() Set the colormap to “hot”.
hsv() Set the colormap to “hsv”.
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 colormap to “inferno”.
install_repl_displayhook() Install a repl display hook so that any stale figure are automatically redrawn when control is returned to the repl.
ioff() Turn interactive mode off.
ion() Turn interactive mode on.
ishold() .
isinteractive() Return status of interactive mode.
jet() Set the colormap to “jet”.
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 colormap to “magma”.
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.
nipy_spectral() Set the colormap to “nipy_spectral”.
over(func, *args, **kwargs) .
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 colormap to “pink”.
plasma() Set the colormap to “plasma”.
plot(*args, **kwargs) Plot y versus x as lines and/or markers.
plot_date(x, y[, fmt, tz, xdate, ydate, …]) Plot data that contains dates.
plotfile(fname[, cols, plotfuncs, comments, …]) Plot the data in a file.
polar(*args, **kwargs) Make a polar plot.
prism() Set the colormap to “prism”.
psd(x[, NFFT, Fs, Fc, detrend, window, …]) Plot the power spectral density.
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 rc params from Matplotlib’s internal defaults.
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, …]) A scatter plot of y vs x with varying marker size and/or color.
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 colormap to “spectral”.
spring() Set the colormap to “spring”.
spy(Z[, precision, marker, markersize, aspect]) 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 at the given grid position.
subplot2grid(shape, loc[, rowspan, colspan, fig]) Create an axis at specific location inside a regular grid.
subplot_tool([targetfig]) Launch a subplot tool window for a figure.
subplots([nrows, ncols, sharex, sharey, …]) Create a figure and a set of subplots
subplots_adjust(*args, **kwargs) Tune the subplot layout.
summer() Set the colormap to “summer”.
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, tick labels, and gridlines.
ticklabel_format(**kwargs) Change the 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 colormap to “viridis”.
vlines(x, ymin, ymax[, colors, linestyles, …]) Plot vertical lines.
waitforbuttonpress(*args, **kwargs) Blocking call to interact with the figure.
winter() Set the colormap to “winter”.
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 axes.
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 current tick locations and labels of the x-axis.
ylabel(s, *args, **kwargs) Set the y-axis label of the current axes.
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 current tick locations and labels of the y-axis.