Polar plot xtick label position

Viewed 78

I have a function, which produces polar plot with matplotlib.

from math import pi

import matplotlib as mpl
import matplotlib.pyplot as plt

first_arg = {
    'Introversion': 17, 'Intuition': 34, 'Feeling': 29, 'Perceiving': 18,
    'Extraversion': 27, 'Sensing': 25, 'Thinking': 23, 'Judging': 16
}
second_arg =  {
    'Introversion': 16, 'Intuition': 25, 'Feeling': 31, 'Perceiving': 15,
    'Extraversion': 22, 'Sensing': 29, 'Thinking': 23, 'Judging': 23
}


def plot_scales_chart(*args):
    scales = [
        'Introversion', 'Intuition', 'Feeling', 'Perceiving',
        'Extraversion', 'Sensing', 'Thinking', 'Judging'
    ]
    angles = [n / float(len(scales)) * 2 * pi for n in range(len(scales))]
    angles += angles[:1]

    mpl.use('agg')

    ax = plt.subplot(polar=True)

    ax.set_theta_offset(pi / 2)
    ax.set_theta_direction(-1)

    plt.xticks(angles[:-1], scales)

    ax.set_rlabel_position(0)
    plt.yticks([15, 25], ["15", "25"], color="grey", size=8)
    plt.ylim(0, 35)

    colors = ['#5159be', '#86e5c7']

    for i, arg in enumerate(args):
        values = []
        for scale in scales:
            values.append(arg[scale])
        values += values[:1]
        ax.plot(angles, values, alpha=0.7, color=colors[i], linewidth=0, linestyle='solid')
        ax.fill(angles, values, colors[i], alpha=0.7)
    
    plt.savefig('chart.png')

enter image description here

I want to move xaxis labels so as not to cross the circle.

How to set label position of particularly one scale or is that possible to move all labels further from the center? What is the best practice there?

0 Answers
Related