Matplotlib 极坐标条形图 - 中间的甜甜圈洞

Matplotlib polar bar chart - donut hole in middle

我有以下图表和代码:

代码:

def generate_chart_capability(student, df):
    # canvas sizing
    plt.figure(figsize=(10, 10))
    # plot polar axis
    ax = plt.subplot(111, polar=True, projection='polar')
    ax.set_theta_direction(-1)
    ax.set_theta_offset(np.pi / 1.6)
    ax.set_xticklabels([])
    ax.set_yticklabels([1, 2, 3, 4, 5], size=21)

    # Compute the width of each bar. In total, we have 2*Pi = 360°
    width = 2 * np.pi / len(df.index)
    # Compute the angle each bar is centered on:
    indexes = list(range(1, len(df.index) + 1))
    angles = [element * width for element in indexes]
    # Compute the heights
    heights = df.Value
    # Colour the bars
    c = ['#054998', '#3660B3', '#5579CF', '#7392EB', '#90ADFF', '#ADC8FF']

    # Draw the bars
    ax.bar(x=angles, height=heights, width=width, color=c, bottom=0, linewidth=2, edgecolor="white")
    ax.set_ylim([0, 5])

    # Save the figure
    plt.savefig('app/static/output/capability_chart_' + student + '.png')
    
    # Close the figure
    plt.clf()

图表:

我想在 0 和 1 之间的图表中间有一个甜甜圈孔(基本上未填充),因为我的数据中没有这个值范围。

我尝试在 ax.bar 中设置 bottom=1,但这只会将数据值加 1。

如何实现这个未填充的第一个区域?

I have tried to set bottom=1 in ax.bar but that just adds 1 to the data values.

您可以通过从 heights 中减去 bottom 值来创建洞:

bottom = 1
ax.bar(x=angles, height=heights - bottom, width=width, color=c, bottom=bottom, linewidth=2, edgecolor="white")
#                              ^^^^^^^^^                               ^^^^^^