Cheatsheetscheatsheets PDF
Cheatsheetscheatsheets PDF
plot([X], Y, [fmt], …) API ax.set_[xy]scale(scale, …) from matplotlib import ticker import matplotlib.animation as mpla
ax.[xy]axis.set_[minor|major]_locator(locator)
Cheat sheet Version 3.7.4 X, Y, fmt, color, marker, linestyle linear log
any values values > 0 T = np.linspace(0, 2*np.pi, 100)
S = np.sin(T)
Quick start API scatter(X, Y, …) API symlog logit line, = plt.plot(T, S)
X, Y, [s]izes, [c]olors, marker, cmap any values 0 < values < 1 def animate(i):
import numpy as np line.set_ydata(np.sin(T+i/50))
import matplotlib as mpl anim = mpla.FuncAnimation(
import matplotlib.pyplot as plt bar[h](x, height, …) API
x, height, width, bottom, align, color
Projections API plt.gcf(), animate, interval=5)
plt.show()
subplot(…, projection=p)
X = np.linspace(0, 2*np.pi, 100) p=’polar’ p=’3d’ API
Y = np.cos(X) imshow(Z, …) API Styles API
Z, cmap, interpolation, extent, origin
fig, ax = plt.subplots() plt.style.use(style)
ax.plot(X, Y, color=’green’) contour[f]([X], [Y], Z, …) API p=ccrs.Orthographic() API
X, Y, Z, levels, colors, extent, origin import cartopy.crs as ccrs
fig.savefig(“figure.pdf”) Tick formatters API
plt.show()
pcolormesh([X], [Y], Z, …) API from matplotlib import ticker
ax.[xy]axis.set_[minor|major]_formatter(formatter)
Anatomy of a figure X, Y, Z, vmin, vmax, cmap
Lines API
pie(X, …) API
Z, explode, labels, colors, radius
Quick reminder
Markers API
text(x, y, text, …) API ax.grid()
x, y, text, va, ha, size, weight, transform ax.set_[xy]lim(vmin, vmax)
ax.set_[xy]label(label)
ax.set_[xy]ticks(ticks, [labels])
fill[_between][x](…) API ax.set_[xy]ticklabels(labels)
X, Y1, Y2, color, where Ornaments ax.set_title(title)
ax.tick_params(width=10, …)
ax.legend(…) API ax.set_axis_[on|off]()
handles, labels, loc, title, frameon
Advanced plots fig.suptitle(title)
title
fig.tight_layout()
step(X, Y, [fmt], …) API
Colors API
Legend label plt.gcf(), plt.gca()
X, Y, fmt, color, marker, where handletextpad handle
handlelength
markerfacecolor (mfc)
mpl.rc(’axes’, linewidth=1, …)
’Cn’ Label 1 Label 3 [fig|ax].patch.set_alpha(0)
Subplots layout API ’x’ labelspacing
text=r’$\frac{-e^{i\pi}}{2^n}$’
boxplot(X, …) API
markeredgecolor (mec)
terrain
ocean
cubehelix
rainbow
twilight