我有以下圖表和代碼:
代碼:
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 之間的甜甜圈洞(基本上未填充),因為我的資料中沒有出現這個值范圍。
我試圖設定bottom=1,ax.bar但這只是將 1 添加到資料值。
我怎樣才能實作這個未填充的第一個區域?
uj5u.com熱心網友回復:
我試圖設定
bottom=1,ax.bar但這只是將 1 添加到資料值。
bottom您可以通過從 中減去值來創建孔heights:
bottom = 1
ax.bar(x=angles, height=heights - bottom, width=width, color=c, bottom=bottom, linewidth=2, edgecolor="white")
# ^^^^^^^^^ ^^^^^^

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/447252.html
標籤:Python matplotlib 甜甜圈图
上一篇:為什么視圖不會隨著FuncAnimation繪制的新資料而改變?
下一篇:如何為該圖設定影片以僅顯示下一行
