Python matplotlib:如何绘制底部和最高值的垂直条

发布于 2025-02-11 18:14:35 字数 293 浏览 1 评论 0原文

是否有一种方法可以绘制并非全部从相同基线开始并具有自己的最高值,而是指定底部值和最高值?

换句话说,如果我有以下数据框架:

import pandas as pd
data={'Seconds':[10,20,30,40],'SYS':[95,103,99,112],'DIA':[56,75,62,70]}
df = pd.DataFrame(data)

由此我需要显示4个bar,x轴上的“秒”值和4个bar,以DF ['DIA']值开始在DF [sys']值中的栏

是可能的

Is there a way to plot bars which do not all start from the same baseline and have their own top value, but rather specify both a bottom and a top value?

In other words if I had the following dataframe:

import pandas as pd
data={'Seconds':[10,20,30,40],'SYS':[95,103,99,112],'DIA':[56,75,62,70]}
df = pd.DataFrame(data)

and from this I would need to show 4 bars, with the 'Seconds" values on the X axis and four bars which would start with at the df['DIA'] value and the top of the bar at the df['SYS'] value.

Is it possible? Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩人痒 2025-02-18 18:14:35

您可以执行以下操作:

from matplotlib import pyplot

pyplot.bar(
    x=df['Seconds'],
    height=df['SYS'] - df['DIA'],
    bottom=df['DIA'],
)

输出:

”在此处输入图像说明”

You can do the following:

from matplotlib import pyplot

pyplot.bar(
    x=df['Seconds'],
    height=df['SYS'] - df['DIA'],
    bottom=df['DIA'],
)

output:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文