0

How my polar chart looks like

I'm trying to move the ytick labels so that they are aligned similarly to the axis labels. For example the 'PTS' label is aligned horizontally to its axis, but the ytick labels are shifted to the right.

For the y-value labels i'm using set_rgrids() function to specify angle and label values and tick_params() function to specify label properties like rotation. However this function does not allow me to set label's textbox alignement.

How can i move the y-values to the left so that they are directly under respective axis labels?

for i in range(N):
    #rgrids() for y-labels, tick_params() for properties of y-labels
    axes[i].set_rgrids(rgrids, angle=angles[i], labels=rlabels[i])
    axes[i].tick_params('y', labelrotation=(angles[i]-180 if 90<angles[i]<270 else angles[i]))

    axes[i].set_ylim(ymin, ymax)
    axes[i].set_theta_offset(np.deg2rad(90))
    #text() for axis label
    axes[i].text(np.deg2rad(angles[i]), 1.08*ymax,cat[i], va="center", ha='center',  size=13, rotation=(angles[i]-180 if 90<angles[i]<270 else angles[i]))

Full code:

import numpy as np
import matplotlib.pyplot as pl

def normalize(val, min=0, max=100):
    value = val-min
    range = max-min
    frac = float(value)/range
    return frac*100

cat = ['PTS', 'FG%', 'FGM', '3PM', '3FG%']
N = len(cat)
angles = np.arange(0, 360, 360.0/N)

rcount = 9
ranges = [[5, 33], [30, 55], [3, 10.2], [0.1, 4.5], [22, 46]]
rlabels = [[0]*rcount] * N
ymin = 0
ymax = 100

for i in range(N):
    size = ranges[i][1] - ranges[i][0]
    step = float(size)/rcount
    rlabels[i] = list(np.arange(ranges[i][0] + step, ranges[i][1] + step, step))
    rlabels[i] = [round(x,1) for x in rlabels[i]]

step = (ymax - ymin)/float(rcount)
rgrids = list(np.arange(ymin + step, ymax + step, step))

rect = [0.05, 0.05, 0.8, 0.8]
fig = pl.figure(figsize=(7, 7))

axes = [fig.add_axes(rect, projection="polar", label="axes%d" % i) for i in range(N)]
axes[0].set_thetagrids(angles, labels=cat, fontsize=14, visible=False)#jesli visible=False to trzeba dodac recznie za pomocą ax.text()
axes[0].grid(color='gray', linewidth = 1)

for labels in rlabels:
    labels[0] = ''

for i in range(N):
    axes[i].set_rgrids(rgrids, angle=angles[i], labels=rlabels[i])
    axes[i].tick_params('y',  labelrotation=(angles[i]-180 if 90<angles[i]<270 else angles[i]))
    axes[i].set_ylim(ymin, ymax)
    axes[i].set_theta_offset(np.deg2rad(90))
    axes[i].text(np.deg2rad(angles[i]), 1.08*ymax,cat[i], va="center", ha='center',  size=13, rotation=(angles[i]-180 if 90<angles[i]<270 else angles[i]))

for i in range(1, N):
    axes[i].spines["polar"].set_visible(False)
    axes[i].patch.set_visible(False)
    axes[i].grid("off")
    axes[i].xaxis.set_visible(False)
Domin0
  • 3
  • 3

1 Answers1

0

I think you want to set

ax.text(..., ha='left', rotation_mode="anchor", ...)

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • Seems like a good solution, although i wonder is there a simple way to leave the axis label as they were and move the value labels instead, not the other way around. Anyway thanks for help. – Domin0 Feb 18 '18 at 22:31
  • I guess the solution to that could be similar to the one in [this question](https://stackoverflow.com/questions/46719340/how-to-rotate-tick-labels-in-polar-matplotlib-plot), just for the yticklabels. It is a bit hacky though. – ImportanceOfBeingErnest Feb 18 '18 at 22:45