matplotlib

“hello world”of matplotlib

1
2
3
4
5
6
7
8
9
10
11
x=[1,2,3]
y=[2,3,4]

plt.plot(x,y)

plt.title("Our first Graph",fontdict={'fontname':'Comic Sans MS','fontsize':20})
plt.xlabel('X axis')
plt.ylabel('y axis')


plt.show()

基本运用函数

matplotlib.pyplot模块中:

  • plot()

    画2d图,基本使用方式与matlab中相同

  • figure()

    Create a new figure, or activate an existing figure.

    figure会包装后面的与matplotlib相关代码将画的图放在一个画布中,直到另一个figure被使用

  • xlabel和ylabel

    给轴加标签,也可以理解为坐标轴的名字

  • xticks和yticks

    获取或设置坐标轴的当前刻度位置和标签。

  • legend((line1, line2, line3), (‘label1’, ‘label2’, ‘label3’))

    图例