python绘制条形图

本文介绍了两种在Python中绘制条形图的方法:直接绘制和利用pandas库进行绘制。内容包括参考文献及具体实现步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、直接绘制

参考其他文献

二、利用pandas绘制

df =pd.DataFrame({'lab':['A','B','C'],'val':[10,30,20]})
ax =df.plot.bar(x='lab',y='val',rot=0)

在这里插入图片描述

speed = [0.1,17.5,40,48,52,69,88]
lifespan=[2,8,70,1.5,25,12,28]
index=['snail','pig','elephant','rabbit','giraffe','coyote','horse']
df=pd.DataFrame({'speed':speed,'lifespan':lifespan},index=index)
ax =df.plot.bar(rot=0)

在这里插入图片描述

ax = df.plot.bar(stacked =True)

在这里插入图片描述

import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.rand(6, 4),
                  index=['one', 'two', 'three', 'four', 'five', 'six'],
                  columns=pd.Index(['A', 'B', 'C', 'D'], name='Genus'))
df
df.plot.bar()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值