如何在Python中调整极坐标图的标签角度

时间:2019-04-11 14:20:21

标签: python matplotlib

我已经在matplotlib中使用极坐标图来创建雷达图,并在顶点的顶部标记了数据(x标签)。标签有点长,并且会在图形中出现一些。我想旋转标签,使它们平放或重新放置它们,以免它们移入数据中。但是,我知道的所有操作x标签格式的技巧似乎都无法在极坐标投影中起作用。

我尝试在xlabel()中使用rotation =和其他一些标签,但是它们似乎都不影响标签的位置。

plt.figure(figsize=(10,10))

# labeling and data orgainizing 

categories=['Foo Foo Bar', 'Bar Bar FooBar', 'Foo Bar', 'Foo Bar Foo Bar 
FooBar', 'Foo Bar']
N = len(categories)

values3 = dfggg.loc[3].values.flatten().tolist()
values3 += values3[:1]

values4 = dfggg.loc[4].values.flatten().tolist()
values4 += values4[:1]


values5 = dfggg.loc[5].values.flatten().tolist()
values5 += values5[:1]


values6 = dfggg.loc[6].values.flatten().tolist()
values6 += values6[:1]


#setting up the axies
angles = [n / float(N) * 2 * pi for n in range(N)]
angles += angles[:1]

# Initialise the radar plot
ax = plt.axes(polar=True)

# Draw one axe per variable + add labels labels yet
plt.xticks(angles[:-1], categories, color='black', size=15, rotation=60) 
#rotation does nothing

# Draw ylabels
ax.set_rlabel_position(0)
plt.yticks([.00001], [" "], color="grey", size=7)
plt.ylim(0,1)

# Plot data

ax.plot(angles, values3, linewidth=1, linestyle='solid', 
color='y',alpha=0.5)
ax.plot(angles, values4, linewidth=1, linestyle='solid', 
color='b',alpha=0.5)
ax.plot(angles, values5, linewidth=1, linestyle='solid', 
color='g',alpha=0.5)
ax.plot(angles, values6, linewidth=1, linestyle='solid', 
color='r',alpha=0.5)

# Fill area

ax.fill(angles, values3, 'y', alpha=0.1)
ax.fill(angles, values4, 'b', alpha=0.1)
ax.fill(angles, values5, 'g', alpha=0.1)
ax.fill(angles, values6, 'r', alpha=0.1)

labels = ('Stuff', 'Things','Stuff and Things', 'Things and Stuff')
ax.legend(labels, loc=(0.9, .95), labelspacing=0.1, fontsize='large')

plt.show()

我无法发布图片,因为显然我没有足够的声誉,但是基本上问题是标签遍历数据并且看上去很差。

以下是图像的链接:https://imgur.com/fTn4Z8M

0 个答案:

没有答案