12 python数据可视化(精讲柱状图&条形图)

00 载入扩展库

import numpy as np
import matplotlib.pyplot as plt

01 柱状图

x=[1,2,3,4,5]
y=[6,10,4,5,1]
colors=['r','b','g','m','c']
plt.bar(x,y,align='center',color=colors)
12 python数据可视化(精讲柱状图&条形图)的图1

02 条形图

x=[1,2,3,4,5]
y=[6,10,4,5,1]
colors=['r','b','g','m','c']
plt.barh(x,y,align='center',color=colors)

12 python数据可视化(精讲柱状图&条形图)的图2

03 改变X轴和Y轴的坐标标识

x=[1,2,3,4,5]
y=[6,10,4,5,1]
colors=['r','b','g','m','c']
plt.bar(x,y,align='center',color=colors)
plt.xticks(x,['a','b','c','d','e'])

12 python数据可视化(精讲柱状图&条形图)的图3

x=[1,2,3,4,5]
y=[6,10,4,5,1]
colors=['r','b','g','m','c']
plt.barh(x,y,align='center',color=colors)
plt.yticks(x,['a','b','c','d','e'])

12 python数据可视化(精讲柱状图&条形图)的图4

04 堆积(叠加)

x=[1,2,3,4,5]
y=[6,10,4,5,1]
y1=[2,6,3,8,5]
colors=['r','b','g','m','c']
plt.bar(x,y,align='center',color=colors)
plt.bar(x,y1,align='center',bottom=y,color='k')
plt.xticks(x,['a','b','c','d','e'])

12 python数据可视化(精讲柱状图&条形图)的图5

x=[1,2,3,4,5]
y=[6,10,4,5,1]
y1=[2,6,3,8,5]
colors=['r','b','g','m','c']
plt.barh(x,y,align='center',color=colors)
plt.barh(x,y1,align='center',left=y,color='k')
plt.yticks(x,['a','b','c','d','e'])

12 python数据可视化(精讲柱状图&条形图)的图6

05 并列

x=np.arange(1,6,1)
y=[6,10,4,5,1]
y1=[2,6,3,8,5]
colors=['r','b','g','m','c']
plt.bar(x,y,align='center',width=0.4,color=colors)
plt.bar(x+0.4,y1,align='center',width=0.4,color='k')
plt.xticks(x+0.2,['a','b','c','d','e'])

12 python数据可视化(精讲柱状图&条形图)的图7

x=np.arange(1,6,1)
y=[6,10,4,5,1]
y1=[2,6,3,8,5]
colors=['r','b','g','m','c']
plt.barh(x,y,align='center',height=0.4,color=colors)
plt.barh(x+0.4,y1,align='center',height=0.4,color='k')
plt.yticks(x+0.2,['a','b','c','d','e'])

12 python数据可视化(精讲柱状图&条形图)的图8

06 hatch的使用

x=[1,2,3,4,5]
y=[6,10,4,5,1]
colors=['r','b','g','m','c']
plt.bar(x,y,align='center',color=colors,hatch='//')

12 python数据可视化(精讲柱状图&条形图)的图9

x=[1,2,3,4,5]
y=[6,10,4,5,1]
colors=['r','b','g','m','c']
plt.barh(x,y,align='center',color=colors,hatch='//')

12 python数据可视化(精讲柱状图&条形图)的图10



默认 最新
当前暂无评论,小编等你评论哦!
点赞 2 评论 收藏
关注