ZCQ
绘制散点图
与绘制折线图唯一区别:
折线图:
plt.plot(x,_x)
散点图:
plt.scatter(x,_x)
条形图(竖)
from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font=font_manager.FontProperties(fname="C:\WINDOWS\FONTS\MSYHL.TTC")
a=["战狼","速度与激情8","变形金刚5:最后的骑士","摔跤吧!爸爸","加勒比海盗5:死无对证","西游伏魔篇"]
b=[56,27,17,19,15,18]
plt.figure(figsize=(20,15),dpi=200)
plt.bar(range(len(a)),b,width=0.2)
plt.xticks(range(len(a)),a,fontproperties=my_font,rotation=90)
plt.show()
条形图(横)
from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font=font_manager.FontProperties(fname="C:\WINDOWS\FONTS\MSYHL.TTC")
a=["战狼","速度与激情8","变形金刚5:最后的骑士","摔跤吧!爸爸","加勒比海盗5:死无对证","西游伏魔篇"]
b=[56,27,17,19,15,18]
plt.figure(figsize=(20,15),dpi=200)
plt.barh([0,1,2,3,4,5],b,height=0.2)
plt.yticks([0,1,2,3,4,5],a,fontproperties=my_font,rotation=90)
plt.show()
直方图:
import numpy as np
a=np.random.randint(10,55,size=100)
a[0]=10
a[1]=55#让a中10和55都能取到,保证下面(max(a)-min(a))//d 是整数
d=3
num_bins=(max(a)-min(a))//d
plt.figure(figsize=(20,8),dpi=80)
plt.hist(a,num_bins,normed=True)#normed:y轴的分布概率
plt.xticks(range(min(a),max(a)+d,d))
plt.grid()
plt.show()
运行结果: