matplotlib.pyplot Notebook
由于使用emacs-org进行编辑,为方便暂且使用英文
Table of Contents
- basic point
- basic elements
- line graph
- histogram
- pie chart
- bar graph
- scatter
- subplot
- image
- fill
- stuffs
- colors
- xkcd-mode
basic point
hold: whether to hold all lines on same picture,
or del previous lines when drawing new ones
basic elements
axis: x, y, banners, scales, limits
gridline: .lw: linewidth, .alpha: alpha
line graph
axis:
# simply use axis()
plt.axis([0, 10, 0, 1])
# or use following methods
plt.xlim(0, 10)
plt.ylim(0, 1)
line
markers
-
linestyles
’-’ solid line style
’–’ dashed line style
’-.’ dash-dot line style
’:’ dotted line style
-
dot-markers
’.’ point marker
’,’ pixel marker
’o’ circle marker
’v’ triangle_down marker
’^’ triangle_up marker
’<’ triangle_left marker
’>’ triangle_right marker
’1’ tri_down marker
’2’ tri_up marker
’3’ tri_left marker
’4’ tri_right marker
’s’ square marker
’p’ pentagon marker
‘*’ star marker
’h’ hexagon1 marker
’H’ hexagon2 marker
’+’ plus marker
’x’ x marker
’D’ diamond marker
’d’ thin_diamond marker
’|’ vline marker
’_’ hline marker
-
colors
’b’ blue
’r’ red
’g’ green
’c’ cyan
’m’ magenta
’y’ yellow
’w’ white
’k’ black
-
linewidth
(real number)
method 1
directly set in plot()
plt.plot(x, y, ',:m', linewidth = 0.2)
plt.plot(x, y, color = 'm', linestyle = ':', marker = ',',
linewidth = 0.2)
plt.plot(x, y, color = 'magenta',
linestyle = 'dotted',
marker = 'pixel',
linewidth = 0.2)
method 2
set with set()
line = plt.plot(range(5))[0]
line.set(color = 'm', linewidth = 0.2, )
method 3
set multiple lines with setp()
lines = plt.plot(range(5), range(8, 13))
plt.setp(lines, color = 'm', linewidth = 0.2, )
legend, label and title
remember to use legend() to activate labels
plt.plot(x, y, label = 'y = sinx')# set a legend
plt.legend()# activate
plt.xlabel('x axis')
plt.ylabel('y axis'