日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 条形图图注怎么集中注意力_如何用每个条形图的总和(Matplotlib)注释堆积条形图?...

發布時間:2025/4/5 python 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 条形图图注怎么集中注意力_如何用每个条形图的总和(Matplotlib)注释堆积条形图?... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我有一個分組條形圖,每個條形圖都是堆疊的。在

我已經用單獨的值注釋了堆棧的每個部分,現在我想將這些值相加,并注釋每個條的總值(高度)。我希望這個注釋在每個條的頂部。在

這是我使用的兩個數據幀之一:df_title = pd.DataFrame(index=['F','M'],

data={'<10':[2.064897, 1.573255], '10-12':[3.933137, 4.326450], '13-17':[9.242871, 16.715831],

'18-24':[10.226155, 12.487709], '18-24':[8.161259, 10.717797], '35-44':[5.801377, 4.916421],

'45-54':[3.539823, 2.851524], '55+':[1.671583, 1.769912]})

在繪圖之前,我將兩個數據幀(df_title和df_comps)轉換成numpy數組。在

^{pr2}$

以下是完整代碼:df_title

df_comps

len = df_title.shape[1]

df_title_concat = np.concatenate((np.zeros((len,1)), df_title.T.values), axis=1)

df_comps_concat = np.concatenate((np.zeros((len,1)), df_comps.T.values), axis=1)

fig = plt.figure(figsize=(20,10))

ax = plt.subplot()

title_colors = ['skyblue', 'royalblue']

comps_colors = ['lightgoldenrodyellow', 'orange']

for i in range(1,3):

for j in list(range(0, df_title.shape[1]-1)):

j += 1

ax_1 = ax.bar(j, df_title_concat[j,i], width=-0.4, bottom=np.sum(df_title_concat[j,:i]), color = title_colors[i-1],

edgecolor='black', linewidth=3, align='edge')

for p in ax_1.patches:

width, height = p.get_width(), p.get_height()

x, y = p.get_xy()

if height > 2:

ax.annotate('{:.2f}%'.format(height), (p.get_x()+0.875*width, p.get_y()+.4*height),

fontsize=16, fontweight='bold', color='black')

ax_2 = ax.bar(j, df_comps_concat[j,i], width=0.4, bottom=np.sum(df_comps_concat[j,:i]), color = comps_colors[i-1],

edgecolor='black', linewidth=3, align='edge')

for p in ax_2.patches:

width, height = p.get_width(), p.get_height()

x, y = p.get_xy()

if height > 2:

ax.annotate('{:.2f}%'.format(height), (p.get_x()+0.15*width, p.get_y()+.4*height),

fontsize=16, fontweight='bold', color='black')

{1美元^

總結

以上是生活随笔為你收集整理的python 条形图图注怎么集中注意力_如何用每个条形图的总和(Matplotlib)注释堆积条形图?...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。