How to align or label spider plot variable name?

霸气de小男生 提交于 2021-01-29 06:08:50

问题


I have the following spider plot:

I would like to align the variable names (i.e., LABEL_A, LABEL_B, LABEL_C, LABEL_D, VISIT_NAME) such that it is outside the plot (not touching the plot). How do I do that?

What I tried so far?

plt.xticks(angles[:-1], df1, color='black', size=12, ha = 'center')

What should I add to justify the label names /the label names should not tough the graph?

Thanks in advance!


回答1:


Adjust the horizontal alignment after you plotted the graph depending on the angle position of the label:

Example:

import matplotlib.pyplot as plt
import numpy as np

ax = plt.subplot(projection='polar')
ax.set_thetagrids(np.degrees(ax.get_xticks()), ['long label']*8)
for t in plt.thetagrids()[1]:
    a = np.degrees(t.get_position()[0])
    if a < 90 or a > 270:
        t.set_ha('left')
    elif a > 90 and a < 270:
        t.set_ha('right')
    else:
        t.set_ha('center')

This is for default theta origin of 0. If you change it you'll have to adjust the angle conditioins accordingly.



来源:https://stackoverflow.com/questions/65813366/how-to-align-or-label-spider-plot-variable-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!