Basic plots Scales Tick locators Animation …

Basic plots

Scales

API

1234567 Cheat sheet

Version 3.5.0

1234567 1234567 002...005 2 0 2 002...005101010 Quick start

API

2.5 2.5 import numpy as np 10010 import matplotlib as mpl 1234567 1234567 import matplotlib.pyplot as plt

X = np.linspace(0, 2*np.pi, 100)

1234567 1234567 Y = np.cos(X)

fig, ax = plt.subplots() ax.plot(X, Y, color='green')

1234567 1234567 fig.savefig("figure.pdf")

fig.show()

0123 1234567 Anatomy of a figure

321 Anatomy of a figure

1234567 3210123 4

Title

Major tick

Minor tick

1234567 1234567 3

Major tick label

Grid (linLeinpelot)

Blue signal Red signal

Legend

Y axis label

1234567 12T3E45X6T7 2

Y axis label

1234567 1234567 1

(scMatatrekreprslot)

1234567 Figure

Axes

(linLeinpelot)

Spines

plot([X],Y,[fmt],...)

API

X, Y, fmt, color, marker, linestyle

scatter(X,Y,...)

API

X, Y, [s]izes, [c]olors, marker, cmap

bar[h](x,height,...)

API

x, height, width, bottom, align, color

imshow(Z,...)

API

Z, cmap, interpolation, extent, origin

contour[f]([X],[Y],Z,...) API X, Y, Z, levels, colors, extent, origin

pcolormesh([X],[Y],Z,...) API X, Y, Z, vmin, vmax, cmap

quiver([X],[Y],U,V,...)

API

X, Y, U, V, C, units, angles

pie(X,...)

API

Z, explode, labels, colors, radius

text(x,y,text,...)

API

x, y, text, va, ha, size, weight, transform

fill[_between][x](...)

API

X, Y1, Y2, color, where

Advanced plots

ax.set_[xy]scale(scale,...)

linear

log

-

+ any values 0

+ values > 0

symlog

2 1 0logit

-

+ any values

00

Projections

0

12

1 0 < values < 1

API

subplot(...,projection=p)

p='polar'

p='3d'

p=Orthographic()

API

from cartopy.crs import Cartographic

Lines

API

linestyle or ls

"-"

":"

"--"

"-."

capstyle or dash_capstyle

(0,(0.01,2))

"butt"

"round"

"projecting"

Markers

API

'.' 'o' 's' 'P' 'X' '*' 'p' 'D' '' '^' 'v'

'1' '2' '3' '4' '+' 'x' '|' '_' 4 5 6 7

'$ $''$ $''$ $''$ $''$ $''$ $''$ $''$ $''$ $''$ $''$ $''$ $'

markevery

10

[0, -1]

(25, 5)

[0, 25, -1]

0

1234567 0

0.25 0.50 0.75 Minor tick label

1

1.25

1.50

1.7X5axis2

2.25 label

2.50

2.75

3

3.25 3.50 3.75

4

X axis label

Subplots layout

API

1234567 1234567 subplot[s](rows,cols,...) API

fig, axs = plt.subplots(3, 3)

1234567 246 G = gridspec(rows,cols,...) API

ax = G[0,:]

123456711111111 1234567 ax.inset_axes(extent)

API

1234567 1234567 d=make_axes_locatable(ax) API

ax = d.new_horizontal('10%')

1234567 1234567 Getting help 1234567 1234567 ?

H matplotlib/matplotlib/issues discourse. W questions/tagged/matplotlib

1234567 1234567 gitter.im/matplotlib

F matplotlib

1234567 a Matplotlib users mailing list

step(X,Y,[fmt],...) X, Y, fmt, color, marker, where

boxplot(X,...) X, notch, sym, bootstrap, widths

errorbar(X,Y,xerr,yerr,...) X, Y, xerr, yerr, fmt

hist(X, bins, ...) X, bins, range, density, weights

violinplot(D,...) D, positions, widths, vert

barbs([X],[Y], U, V, ...) X, Y, U, V, C, length, pivot, sizes

eventplot(positions,...) positions, orientation, lineoffsets

hexbin(X,Y,C,...) X, Y, C, gridsize, bins

API API API API API API API API

Colors

API

1

0 1

0

C0 b

C1

2g

C2

4

C3

r6

C4 C5 C6 C7 C8 C9 'Cn'

c 8 m 10 y 12 k 14 w 16 'x'

01 01 01 0

DarkRed

0 2 (1,0,0) 0 2 #FF0000 0 2 0.0 0.1 02

Firebrick Crimson IndianRed Salmon

4 6 8 10 12 14 16 (1,0,0,0.75) (1,0,0,0.5) (1,0,0,0.25) 4 6 #FF0000BB 8 10 #FF000088 12 14 #FF000044 16 4 0.2 6 0.3 0.4 80.5 10 0.6 0.7 102.8 01.94 1.016 4 6 8 10 12 14 16

'name' (R,G,B[,A]) '#RRGGBB[AA]' 'x.y'

Colormaps plt.get_cmap(name) Uniform

Sequential

Diverging

Qualitative Cyclic

API

viridis magma plasma

Greys YlOrBr Wistia

Spectral coolwarm RdGy

tab10 tab20

twilight

Tick locators

API

from matplotlib import ticker ax.[xy]axis.set_[minor|major]_locator(locator)

ticker.NullLocator()

ticker.MultipleLocator(0.5)

0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0

ticker.FixedLocator([0, 1, 5])

0

1

5

ticker.LinearLocator(numticks=3)

0.0

2.5

5.0

ticker.IndexLocator(base=0.5, offset=0.25)

0.25 0.75 1.25 1.75 2.25 2.75 3.25 3.75 4.25 4.75

ticker.AutoLocator()

0

1

2

3

4

5

ticker.MaxNLocator(n=4)

0.0

1.5

3.0

4.5

ticker.LogLocator(base=10, numticks=15)

103

104

105

106

107

108

109

1010

Tick formatters

API

from matplotlib import ticker ax.[xy]axis.set_[minor|major]_formatter(formatter)

ticker.NullFormatter()

ticker.FixedFormatter(['zero', 'one', 'two', ])

zero

one

two

three

four

five

ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)

[0.00]

[1.00]

[2.00]

[3.00]

[4.00]

[5.00]

ticker.FormatStrFormatter('>%d ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download