tf好朋友之matplotlib的使用——bar柱状图的绘制

tf好朋友之matplotlib的使用——bar柱状图的绘制

除了散点图,还有柱状图噢!
在这里插入图片描述

柱状图绘制常用函数

plt.bar()

plt.bar(
	x, 
	height, 
	width=0.8, 
	bottom=None, 
	*, 
	align='center',
	data=None, 
	**kwargs)

常用参数如下:
x:每个柱子的x坐标。
height:每个柱子的高度。
width:每个柱子的宽度。
align:每个柱子相对于其对应的x的位置。常见的是center,位于对应的x的中间。
color:用于设置柱子的颜色。
edgecolor:用于设置柱子边缘的颜色。
alpha:用于设置透明度。

应用示例

import matplotlib.pyplot as plt
import numpy as np

random_x = np.arange(5)
random_y = abs(np.random.uniform(0,1,5))
color = ['#EE6363','#CD5555','#8B6969','#FFC1C1','#FFA07A']
plt.bar(random_x,random_y,color = color,edgecolor='white',alpha = 0.5)
plt.ylim(0,1)
for x,y in zip(random_x,random_y):
    plt.text(x-0.15,y+0.02,'%.2f'%y)
plt.show()

结果为:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bubbliiiing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值