首页 > 解决方案 > Python圆形条形图中心太小

问题描述

谁能帮我弄清楚如何使中间的圆圈变大,这样我的酒吧就不会全部挤在一起???我真的试图调整 plt.figure(figsize=(15,30)) 中的大小,但它只会使最高的条变得更高,而没有改变中间圆(空心部分)的任何内容。

我得到的图像看起来像这样

我希望得到这样的输出:

我的代码:

#plot firm_x_sales by cat_code and fund_category



# remove grid
plt.axis('off')

# Set the coordinates limits
upperLimit = 100
lowerLimit = 30

# Compute max and min in the dataset
max = df8['firm_x_sales'].max()

# Let's compute heights: they are a conversion of each item value in those new coordinates
# In our example, 0 in the dataset will be converted to the lowerLimit (10)
# The maximum will be converted to the upperLimit (100)
slope = (max - lowerLimit) / max
heights = slope * df8.firm_x_sales + lowerLimit 

# Compute the width of each bar. In total we have 2*Pi = 360°
width = 2*np.pi / len(df8.index)

# Compute the angle each bar is centered on:
indexes = list(range(1, len(df8.index)+1))
angles = [element * width for element in indexes]
angles


# initialize the figure
plt.figure(figsize=(20,20))
ax = plt.subplot(111, polar=True)
plt.axis('off')

# Draw bars
bars = ax.bar(
    x=angles, 
    height=heights, 
    width=width, 
    bottom=lowerLimit,
    linewidth=2, 
    edgecolor="white",
    color="#61a4b2",
)


# little space between the bar and the label
labelPadding = 10

# Add labels
for bar, angle, height, label in zip(bars,angles, heights, df8["fund_category"]):

    # Labels are rotated. Rotation must be specified in degrees :(
    rotation = np.rad2deg(angle)

    # Flip some labels upside down
    alignment = ""
    if angle >= np.pi/2 and angle < 3*np.pi/2:
        alignment = "right"
        rotation = rotation + 180
    else: 
        alignment = "left"

    # Finally add the labels
    ax.text(
        x=angle, 
        y=lowerLimit + bar.get_height() + labelPadding, 
        s=label, 
        ha=alignment, 
        va='center', 
        rotation=rotation, 
        rotation_mode="anchor",
        fontsize=5) 

使用的数据:

f und_category cat_codefirm_x_sales \ 0 银行贷款 GFICC 3.06E+07 1 中国区 EQ 7.94E+05 2 大宗商品 > 篮子 GFICC 1.52E+05 3 公司债券 GFICC 5.92E+07 4 多元化 > 新兴市场 MAS 4.94E+08 5 Emerging Markets Bond GFICC 9.96E+07 > 6 Emerging-Markets Local-Currency Bond GFICC 6.12E+07 7 Europe > Stock EQ 5.05E+07 8 Foreign Large Blend EQ 4.38E+08 9 Foreign Large > Value EQ 1.15E+08 10 高收益债券 GFICC 6.82E+08 > 11 通胀保值债券 GFICC 2.17E+07 12 中期 > 政府 GFICC 1.41E+08 13 中期债券 GFICC 3.28E+09 > 14 大型混合 EQ 9.87E+08 15 大型增长 EQ 1.42E+09 16 大 > 价值 EQ 3.32E+09 17 拉丁美洲股票 EQ 2.22E+06 18 多空 > 股票 EQ 1.48E+07 19 市场中性 EQ 9。04E+06 20 Mid-Cap > Blend EQ 1.48E+09 21 Mid-Cap Growth EQ 3.70E+08 22 Multi Asset > Alloc MAS 2.07E+09 23 Multialternative MAS 2.37E+07 24 Muni California > Intermediate GFICC 2.71E+ 07 25 Muni National Interm GFICC 5.94E+07 > 26 Muni National Long GFICC 1.69E+07 27 Muni National > Short GFICC 1.19E+08 28 Muni New York Intermediate GFICC 1.01E+07 > 29 Muni Ohio GFICC 2.82E+06 30 Nontrad Multisect Bond GFICC 1.84E+09 > 31 基于期权的 EQ 4.00E+08 32 房地产 EQ 3.81E+07 33 Short > Government GFICC 2.04E+06 34 Short-Term Bond GFICC 2.63E+08 35 Small > Blend EQ 1.07E+09 36 Small Growth EQ 1.51E+08 37 Small > Value EQ 4.24E+08 38 Target-Date 2015 MAS 2.39E+06 39 Target-Date > 2020 MAS 5.85E+06 40 Target-Date 2025 MAS 7.65E +06 41 目标日期 >2030 MAS 9.33E+06 42 目标日期 2035 MAS 5.64E+06 43 目标日期 > 2040 MAS 7.34E+06 44 目标日期 2045 MAS 4.77E+06 45 目标日期 > 2050 MAS 5.17E+06 46 目标-Date 2055 MAS 3.24E+06 47 Target-Date > 2060+ MAS 1.68E+05 48 Target-Date Retirement MAS 1.55E+07 > 49 Ultrashort Bond GFICC 7.47E+07 50 World Stock EQ 6.46E+06

标签: pythonmatplotlib

解决方案


推荐阅读