是否有一种方法可以将以下条绘制到一个分组的小号的条形图中,我可以将其表示为单个栏,在该条形条上,它可以分开,更像是重叠。
我的想法是使用堆叠栏,但问题是我不希望像在此处那样将值求和
我的数据看起来像这样:
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. 
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?

发布评论