Matplotlib常用API

导入库

improt matplotlib.pyplot  as plt
方法 用法
plt.title()
(图的标题)
plt.title(“Matplotlib demo”)
plt.xlabel()
(X轴描述)
plt.xlabel(“x axis caption”)
plt.ylabel()
(Y轴描述)
plt.ylabel(“y axis caption”)
plt.plot()
(画图)
plt.plot(x,y)
plt.show()
显示
plt.show()
plt.subplot()
(子图绘制)
plt.subplot(2, 1, 1) 21 第一个图
plt.subplot(2, 1, 2) 2
1 第二个图
plt.bar(x, y, align = ‘center’)
(条状图)
plt.figure()
存放实例代码生成的图片
figure(figsize=(8,6), dpi=80)
创建一个 8 * 6 点(point)的图,并设置分辨率为 80
xlim
横轴的上下限
xlim(-4.0,4.0)
ylim
纵轴的上下限
ylim(-1.0,1.0)
legend())<图例位置> legend(loc=‘upper left’)
scatter
scatter(X,Y)
contourf
等高线
contourf(X, Y, f(X,Y), 8, alpha=.75, cmap=‘jet’)

中文支持

import matplotlib as mpl
# matplotlib 中文 负号的支持
mpl.rcParams["font.family"] = "SimHei"
mpl.rcParams["axes.unicode_minus"] = False

猜你喜欢

转载自blog.csdn.net/u014258362/article/details/85091706