matplotlib的基本用法(八)——绘制柱状图
来源:互联网 发布:ubuntu恢复初始命令 编辑:程序博客网 时间:2024/05/19 10:40
文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
本文主要使用matplotlib进行柱状图的绘制。
- Demo
import matplotlib.pyplot as pltimport numpy as np# 数据数目n = 10x = np.arange(n)# 生成数据, 均匀分布(0.5, 1.0)之间y1 = (1 - x / float(n)) * np.random.uniform(0.5, 1.0, n)y2 = (1 - x / float(n)) * np.random.uniform(0.5, 1.0, n)# 绘制柱状图, 向上plt.bar(x, y1, facecolor = 'blue', edgecolor = 'white')# 绘制柱状图, 向下plt.bar(x, -y2, facecolor = 'green', edgecolor = 'white')temp = zip(x, y2)# 在柱状图上显示具体数值, ha水平对齐, va垂直对齐for x, y in zip(x, y1): plt.text(x + 0.05, y + 0.1, '%.2f' % y, ha = 'center', va = 'bottom')for x, y in temp: plt.text(x + 0.05, -y - 0.1, '%.2f' % y, ha = 'center', va = 'bottom')# 设置坐标轴范围plt.xlim(-1, n)plt.ylim(-1.5, 1.5)# 去除坐标轴plt.xticks(())plt.yticks(())plt.show()
- 结果
0 0
- matplotlib的基本用法(八)——绘制柱状图
- matplotlib的基本用法(七)——绘制散点图
- matplotlib的基本用法(十)——绘制Image
- Python——使用matplotlib绘制柱状图
- pandas的基本用法(八)——数据的绘制
- matplotlib的基本用法(九)——绘制等高线图
- matplotlib的基本用法(十一)——绘制3D图
- matplotlib的基本用法(十二)——subplot绘制多图
- matplotlib的基本用法(十三)——figure绘制多图
- 八、matplotlib系列---pyplot直方图的绘制
- Python Matplotlib实现三维/四维数据的柱状图绘制
- matplotlib的基本用法(一)——figure的使用
- matplotlib的基本用法(二)——设置坐标轴
- matplotlib的基本用法(三)——调整坐标轴
- matplotlib的基本用法(四)——设置legend图例
- matplotlib的基本用法(五)——添加annotation
- matplotlib的基本用法(六)——设置坐标轴label
- matplotlib的基本用法(十五)——主次坐标轴
- Laravel No supported encrypter found. The cipher and / or key length are invalid
- 这是目前在做的事情的进度
- Android状态模式实践
- 三大常用机密算法原理与基础使用MD5、3DES、RSA
- Medium:Find Largest Value in Each Tree Row
- matplotlib的基本用法(八)——绘制柱状图
- 神经网络压缩(3):Learning both Weights and Connections for Efficient Neural Network
- 周志华《机器学习》课后习题解答系列(六):Ch5.8
- 老司机带你探知存储伸缩之道
- LwIP源代码文件目录解析
- 编码解码
- 数据结构简单应用
- Java对MySQL中的数据实现增查删改
- Android6.0 最新简洁配置权限,APP专用