在交互环境中查看英文帮助文档:
import matplotlib.pyplot as plt
help(plt.plot)
#单条线:
plot([x], y, [fmt], data=None, **kwargs)
#多条线一起画
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)
fmt
可选参数[fmt]
是一个字符串来定义图的基本属性如:颜色(color
),点型(marker
),线型(linestyle
),
具体形式 fmt = '[color][marker][line]'
,如指定fmt为'bo-'
# 蓝色圆点实线
fmt
接收的是每个属性的单个字母缩写,例如:plot(x, y, 'bo-') # 蓝色圆点实线
若属性用的是全名则不能用*fmt
*参数来组合赋值,应该用关键字参数对单个属性赋值如:
plot(x,y2,color='green', marker='o', linestyle='dashed', linewidth=1, markersize=6)
plot(x,y3,color='#900302',marker='+',linestyle='-')
也可以对关键字参数color
赋十六进制的RGB字符串如 color='#900302'
============= ===============================
character color
============= ===============================
``'b'`` blue 蓝
``'g'`` green 绿
``'r'`` red 红
``'c'`` cyan 蓝绿
``'m'`` magenta 洋红
``'y'`` yellow 黄
``'k'`` black 黑
``'w'`` white 白
============= ===============================
Markers
**用关键字参数对单个属性赋值,如:marker='+'
这个只有简写,英文描述不被识别
============= ===============================
character description
============= ===============================
``'.'`` 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 x标记
``'D'`` diamond marker 方菱形标记
``'d'`` thin_diamond marker 瘦菱形标记
``'|'`` vline marker 竖线标记
``'_'`` hline marker 下划线标记
============= ===============================
Line Styles
**,用关键字参数对单个属性赋值,如:linestyle='-'
============= ===============================
character description
============= ===============================
``'-'`` solid line style 实线
``'--'`` dashed line style 虚线
``'-.'`` dash-dot line style 点画线
``':'`` dotted line style 点线
============= ===============================