带有标签的同一栏上的分位数

发布于 2025-02-08 08:44:39 字数 1788 浏览 0 评论 0 原文

是否有一种方法可以将以下条绘制到一个分组的小号的条形图中,我可以将其表示为单个栏,在该条形条上,它可以分开,更像是重叠。

我的想法是使用堆叠栏,但问题是我不希望像在此处那样将值求和

我的数据看起来像这样:

    customer avg_price  avg_price2  p_50    p_75    p_90    count
0   A   2.84    5.7681  2.72    3.42    4.090   526181
1   B   2.73    6.3373  2.57    3.52    4.360   646022
2   C   2.51    21.4732 1.67    3.35    5.442   1140
3   D   2.19    9.3906  1.87    3.15    3.430   110729
4   E   2.19    5.6669  2.00    2.70    3.630   703413

我想将P_50,P_75,P_90绘制为列。

因此,我试图通过将每个栏重叠起来,从最低到最低。问题是这些是百分位数,我不能简单地堆叠它们,因为它们不一定会增加总价值。

fig, ax = plt.subplots(figsize=(15,11))
df.sort_values(by='avg_price').plot.barh(x='customer', y=['p_90'], width=0.75, ax=ax, color='darkblue');
df.sort_values(by='avg_price').plot.barh(x='customer', y=['p_75'], width=0.75, ax=ax);
df.sort_values(by='avg_price').plot.barh(x='customer', y=['p_50'], width=0.75, ax=ax, color='lightblue');

ax.bar_label(ax.containers[0], labels=[f'{p:.2f}' for p in df.sort_values(by='avg_price')['p_90']], label_type='center');
ax.bar_label(ax.containers[0], labels=[f'{p:.2f}' for p in df.sort_values(by='avg_price')['p_75']], label_type='center');
ax.bar_label(ax.containers[0], labels=[f'{p:.2f}' for p in df.sort_values(by='avg_price')['p_50']], label_type='center');

在试图用适当的值标记它们重叠的值时。 如何正确标记每个部分?

Is there a way to plot the following bar into a grouped barplot that I could represent it as a single bar where it would be separated, more like overlapping. enter image description here

What I thought about is using a stacked bar but the problem is I do not want the values to be summed up like here Stacked Bar Chart with Centered Labels

My data looks something like this:

    customer avg_price  avg_price2  p_50    p_75    p_90    count
0   A   2.84    5.7681  2.72    3.42    4.090   526181
1   B   2.73    6.3373  2.57    3.52    4.360   646022
2   C   2.51    21.4732 1.67    3.35    5.442   1140
3   D   2.19    9.3906  1.87    3.15    3.430   110729
4   E   2.19    5.6669  2.00    2.70    3.630   703413

I want to plot p_50, p_75, p_90 as columns.

So I tried to plot them by overlapping each bar starting with the largest to the lowest. The thing is these being percentiles I can't simply stacked them since they don't necessarily add to a total value.

fig, ax = plt.subplots(figsize=(15,11))
df.sort_values(by='avg_price').plot.barh(x='customer', y=['p_90'], width=0.75, ax=ax, color='darkblue');
df.sort_values(by='avg_price').plot.barh(x='customer', y=['p_75'], width=0.75, ax=ax);
df.sort_values(by='avg_price').plot.barh(x='customer', y=['p_50'], width=0.75, ax=ax, color='lightblue');

ax.bar_label(ax.containers[0], labels=[f'{p:.2f}' for p in df.sort_values(by='avg_price')['p_90']], label_type='center');
ax.bar_label(ax.containers[0], labels=[f'{p:.2f}' for p in df.sort_values(by='avg_price')['p_75']], label_type='center');
ax.bar_label(ax.containers[0], labels=[f'{p:.2f}' for p in df.sort_values(by='avg_price')['p_50']], label_type='center');

While trying to label each column with their proper the values they overlap.
How can I properly label each section?

enter image description here

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文