x = np.linspace(-10,10,5)
y = x **2
plt.plot(x, y,c='red',linestyle='-.',linewidth=1,marker='o',markerfacecolor='blue')
plt.show()
条形图(bar)
width:长条形宽度(横向为height),默认值0.8
bottom:坐标原点y起始值
color:颜色
y =[20,10,30,25,15]
x =range(len(y))
bar_width =10
bar_width =10
plt.bar(x, y, width =0.8,color='blue', bottom=100)# 横向条形图
plt.barh(x, y, height=0.8)
直方图(hist)
bins:直方图的长条形数目,可选项,默认为10
normed:是否将得到的直方图向量归一化,显示频率
color:长条形的颜色
edgecolor:长条形边框颜色
alpha:透明度
mu =100# mean of distribution
sigma =20# standard deviation of distribution
x = mu + sigma * np.random.randn(2000)
plt.hist(x, bins=15,color='red',edgecolor='blue',normed=True)# 两组数据的热点直方图# x = np.random.randn(1000)+2# y = np.random.randn(1000)+3# plt.hist2d(x, y, bins=40)
y = np.arange(1,5)
plt.plot(y, y *2)
plt.grid(True, color='g', linestyle='--', linewidth='2')
图例(legend)
loc 图例的位置
ncol 图例的列数
x = np.arange(1,11,1)
y = x * x
plt.plot(x, x *2, label='Normal')
plt.plot(x, x *3, label='Fast')
plt.plot(x, x *4, label='Faster')
plt.legend(loc=0, ncol=3)# 方法二
plt.plot(x, x *2)
plt.plot(x, x *3)
plt.plot(x, x *4)
plt.legend(['Normal','Fast','Faster'])