我正在嘗試在雷達圖中使用 fill_between 來繪制“環”,遵循此處的 matplotlib 雷達示例:

uj5u.com熱心網友回復:
這是我的評論中建議的解決方案,它依賴于您提供x,y1和y2as args, not kwargs:
....
def fill_between(self, *args, **kwargs):
"""
Override fill_between
- CUSTOM ADDITION TO EXAMPLE -
"""
if len(args) and args[0][0] != args[0][-1]:
args = list(args)
for i, arg in enumerate(args):
args[i] = np.append(arg, arg[0])
return super().fill_between(*args, **kwargs)
....
....
if __name__ == '__main__':
N = 5
theta = radar_factory(N, frame='polygon')
data1 = [2,1.5,3,3,2]
data2 = [1,0.5,2,2,1]
spoke_labels = ['A', 'B', 'C', 'D', 'E']
fig, ax = plt.subplots(figsize=(9, 9), nrows=1, ncols=1,
subplot_kw=dict(projection='radar'))
ax.plot(theta, data1, color='blue')
ax.plot(theta, data2, color='blue')
ax.fill_between(theta, data1, data2, color='red')
ax.fill(theta, data2, facecolor='blue', alpha=0.25)
ax.set_varlabels(spoke_labels)
plt.show()
樣本輸出:

如果需要,您還可以輕松實作kwargs決議以獲得更大的靈活性,但顯然,您失去了 matplotlib 決議的一些靈活性。where但是,如果提供為 len N 的 arg 或 len N 1 的 kwarg ,它仍然會決議:
#where array provided as arg of len N
ax.fill_between(theta, data1, data2, [True, True, False, True, True], color='red')
#or as kwarg of len N 1
#ax.fill_between(theta, data1, data2, where=[True, True, False, True, True, True], color='red')
輸出:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/447239.html
標籤:Python matplotlib
下一篇:比較Pandas中的資料
