【发布时间】:2022-06-11 03:40:12
【问题描述】:
我用matplotlib 创建了一个蜘蛛图,但我不知道如何摆脱与我添加的标签文本重叠的度数标记。由于其他一些兼容性问题,我不得不使用matplotlib v3.2.1。我需要一些帮助来弄清楚如何摆脱 0 度、45 度、90 度等。标签。
chart = plt.figure(figsize=(15,8.5), dpi=150, facecolor=('#D3D3D3'), edgecolor='#000000')
ax = chart.add_subplot(111,polar=True)
ax.set_facecolor('grey')
ax.set_ylim(0,5.1)
ax.set_yticklabels([])
# set guidelines below each of the bars
for i in range(len(dataset['Console'])-1):
ax.vlines(x=Console_loc, ymin=0, ymax=5.1, colors='#D3D3D3', linewidths=.75, alpha=.5, zorder=1)
# Robust Line
ax.plot(resolution, robust, alpha=1, ls='dashed', lw=2, color='#145a32', label='Good')
# 2874A6
# Stable Line
ax.plot(resolution, stable, alpha=1, lw=2, color='#000000',label='Ok')
# 6 Month Avg
# 5DADE2 - cyan
fill = '#7Fb3D5'
ax.plot(Console_loc, dataset['Average'], alpha=.45, color=fill, label='6 month avg')
ax.fill(Console_loc, dataset['Average'], alpha=.35, color=fill)
# Current Month Bars
ax.bar(x=Console_loc, height=dataset['Current'], width=dataset['Bar_Width'], color=dataset['Bar_Color'], label='Current Month', edgecolor=dataset['Border_Color'])
# plot console labels on graph
yloc = 5.3
for i in range(len(dataset['Console'])-1):
if round(np.degrees(Console_loc[i]),1) in np.arange(112.5,270,22.5):
plt.text(x=Console_loc[i],y=yloc, s=dataset['Console'].str[:-5].iloc[i], ha='right', va='center')
elif round(np.degrees(Console_loc[i]),1) in np.arange(292.5,360,22.5) or np.degrees(Console_loc[i]) in np.arange(0,90,22.5):
plt.text(x=Console_loc[i],y=yloc, s=dataset['Console'].str[:-5].iloc[i], ha='left', va='center')
else:
plt.text(x=Console_loc[i],y=yloc, s=dataset['Console'].str[:-5].iloc[i], ha='center', va='center')
# clear angles on outside of chart
# empt = []*17
lines,labels = plt.thetagrids(angles=np.degrees(Console_loc), labels=dataset['Console'], alpha=.001)
# add chart title text
plt.text(x=np.radians(137), y=8.3, s='Testing chart', ha='right', va='center', fontsize='x-large')
plt.grid(False)
plt.legend(loc=(1.2,.8))
plt.show()
图片:
【问题讨论】:
-
投票决定关闭,因为这不是minimal reproducible example。缺少必要的导入和
dataset,并且存在一些缩进错误。请修复这些问题。请发布最少我们需要重现此(或类似)图表的代码量,以便可以理解和回答问题。
标签: python matplotlib