Basic plots Scales Tick locators Animation Quick start

Basic plots

Scales

API

12345671234567 1234567 02..05 2 0 2 02..05 Quick start

API

0.0 0.0101010 import numpy as np 2.5 2.5 import matplotlib as mpl 1234567 1234567 10010 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='C1')

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

fig.show()

1234567 1234567 Anatomy of a figure

Anatomy of a figure

1234567 1234567 4

Title

Major tick

Minor tick

1234567 1234567 3

TEXT Major tick label

Grid (linLeinpelot)

Blue signal Red signal

Legend

Y axis label

1234567 1234567 2 1234567 Y axis label

(scMatatrekreprslot)

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,[cmap],...)

API

Z, cmap, interpolation, extent, origin

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

linear

log

-

+ any values 0

+ values > 0

symlog

2 1 0logit

-

+ any values 0

1 0 < values < 1

00

Projections

12

API

subplot(...,projection=p)

p='polar'

p='3d'

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

p=Orthographic()

API

from cartopy.crs import Cartographic

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

API

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

pie(X,[explode],...)

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

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

1

Advanced plots

1234567 Figure

Axes

(linLeinpelot)

Spines

0

1234567 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 246 subplot[s](rows,cols,...) API

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

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

ax = G[0,:]

1234567 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

matplotlib/matplotlib/issues discourse.

000000000.........00112211006285582602570075205050 questions/tagged/matplotlib 1234567 gitter.im/matplotlib 0505 matplotlib 86402246 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

xcorr(X,Y,...) X, Y, normed, detrend

API API API API API API API API API

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

markevery

10

[0, -1]

(25, 5)

[0, 25, -1]

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

API

plt.get_cmap(name)

Uniform Sequential Diverging Qualitative Cyclic

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(['', '0', '1', ...]) 0 0.25 0.50 1 0.75 0.25 2 0.50 0.75 3 0.25 0.50 0.75 4 0.25 0.50 5

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