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)
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)
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'])
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'])
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'])
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'])
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'])
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'])
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='//')
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='//')
相关知识
python数据可视化之条形图怎么画
Python的Plotly库进行交互式图形可视化
堆叠条形图
使用Altair实现Python交互式数据可视化
Python数据分析数据可视化
【数据可视化中的艺术】:将玫瑰花的美丽转化为数据之美,Python数据图形的精妙运用
从零开始:Python与Jupyter Notebook中的数据可视化之旅
10种数据可视化图表设计师快收好!
利用Python进行数据可视化常见的9种方法!超实用!
Python数据可视化 pyecharts实现各种统计图表过程详解
网址: 12 python数据可视化(精讲柱状图&条形图) https://m.huajiangbk.com/newsview2290139.html
上一篇: 丁香园 Insight 数据库 |
下一篇: 辣海生物数据可视化案例分享 |