堆积图柱形图
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
x = range(1,6)
y = np.random.randint(1,14,5)
y1 = np.random.randint(1,10,5)
plt.bar(x,y,align='center',color='gray',tick_label=[chr(i) for i in range(65,70)],label='样本A')
plt.bar(x,y1,align='center',bottom=y,color='b',label='样本B')
plt.xlabel('value')
plt.ylabel('sample No.')
plt.show()
python高级统计图
堆积条形图
plt.barh(x,y,align='center',color='c',tick_label=[chr(i) for i in range(65,70)],label='样本')
plt.barh(x,y1,align='center',left=y,color='b',label='样本B')
plt.show()
python高级统计图
分组条形图
bar_width = 0.35
tick_label = [chr(i) for i in range(65,70)]
x = np.arange(5)
y = np.random.randint(0,10,5)
y1 = np.random.randint(0,8,5)
plt.bar(x,y,bar_width,color='c',align='center',label='样本A',alpha=0.5)
plt.bar(x+bar_width,y1,bar_width,color='r',align='center',label='样本B',alpha=0.5)
plt.xticks(x+bar_width/2,tick_label)
plt.show()
python高级统计图
分组水平条形图
plt.barh(x,y,bar_width,color='c',align='center',label='A',alpha=.5)
plt.barh(x+bar_width,y1,bar_width,color='b',align='center',label='B',alpha=.5)
plt.yticks(x+bar_width/2,tick_label)
plt.legend()
plt.show()vv
python高级统计图
hatck参数设置填充样式
plt.bar(x,y,align='center',color='c',tick_label=tick_label,hatch='///')
plt.show()
python高级统计图
plt.bar(x,y,align='center',color='c',tick_label=tick_label,hatch='***')
plt.show()
python高级统计图
plt.bar(x,y,align='center',color='c',tick_label=tick_label,hatch='---')
plt.show()
python高级统计图
stackplot()堆积折线图
x = np.arange(1,6,1)
y = np.random.randint(0,10,5)
y1 = np.random.randint(