问题
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