导入
import matplotlib.pyplot as plt
基本图表
用plot方法画出x=(0,10)间sin的图像
x = np.linspace(0, 10, 30)
plt.plot(x, np.sin(x));
用点加线的方式画出x=(0,10)间sin的图像
plt.plot(x, np.sin(x), '-o');
用scatter方法画出x=(0,10)间sin的点图像
plt.scatter(x, np.sin(x));
用饼图的面积及颜色展示一组4维数据
rng = np.random.RandomState(0)
x = rng.randn(100)
y = rng.randn(100)
colors = rng.rand(100)
sizes = 1000 * rng.rand(100)
plt.scatter(x, y, c=colors, s=sizes, alpha=0.3,
cmap='viridis')
plt.colorbar(); # 展示色阶
绘制一组误差为±0.8的数据的误差条图
x = np.linspace(0, 10, 50)
dy = 0.8
y = np.sin(x) + dy * np.random.randn(50)
plt.errorbar(x, y, yerr=dy, fmt='.k')
绘制一个柱状图
x = [1,2,3,4,5,6,7,8]
y = [3,1,4,5,8,9,7,2]
label=['A','B','C','D','E','F','G','H']
plt.bar(x,y,tick_label = label);