直方图:
与条形图显示,直方图的x轴数据是连续的。直方图一般用来描述等距数据
import pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl #解决能显示中文 mpl.rcParams['font.sans-serif']=['SimHei'] #指定默认字体 SimHei为黑体 mpl.rcParams['axes.unicode_minus']=False #用来正常显示负号 plt.title("图标题",fontsize=24) #图的标题 plt.xlabel("x轴标题") plt.ylabel("y轴标题") x=[1,2,3,4,5,6,7,8,9,0,1,1,1,1,1,6,6,6,6,6] y=[1,2,3,4,5,6,7,8,9,0,1,1,7,1,1,6,2,6,7,6] print(x) plt.hist(x,bins=10,color='b',density=0,edgecolor='r') #单变量直方图 #参数1 x轴分布数据 #bins:直方图的长条形数目,可选项,默认为10 #density:是否将得到的直方图向量归一化,可选项,默认为0,代表不归一化,显示频数-出现的次数。normed=1,表示归一化,显示频率-出现的次数/总次数 #edgecolor:长条形边框的颜色 #facecolor:长条形的颜色 #alpha:透明度 #plt.hist2d(x,y,bins=10) #双变量直方图 #用颜色的深浅来表达 plt.show()
效果图