极地Projectiron Matplotlib中的旋转轴标签

时间:2018-08-28 20:57:15

标签: python matplotlib

我正在创建极坐标投影模板, 我想像本question中所述以类似的方式修改轴标签。最重要的是,我想将标签旋转一个自定义角度。

我可以修改标签的颜色,字体大小和其他属性,但是由于某些原因,文本的旋转似乎没有变化。 how my plot looks like currently

    (lines, labels) = self.ax.set_thetagrids(self.angles, labels=self.titles)
    for label, angle in zip(labels, self.angles):
        label.set_size(15)  # works fine
        label.set_color("red")  # works fine
        label.set_rotation(angle)  # doesn't work :(

完整代码:

import numpy as np
import matplotlib.pyplot as pl

class Radar(object):
    def __init__(self, fig, axes_data, rotation=90, rect=None):
        if rect is None:
            rect = [0.1, 0.1, 0.8, 0.8]

        self.n = len(axes_data)
        self.titles = [category[0] for category in axes_data]
        self.angles = np.arange(0, 360, 360.0/self.n)
        self.axes = [fig.add_axes(rect, projection="polar", label="axes%d" % i) for i in range(self.n)]

        self.ax = self.axes[0]
        (lines, labels) = self.ax.set_thetagrids(self.angles, labels=self.titles)
        for label, angle in zip(labels, self.angles):
            label.set_size(15)  # works fine
            label.set_color("red")  # works fine
            label.set_rotation(angle)  # doesn't work :(


        for ax in self.axes[1:]:
            ax.patch.set_visible(False)
            ax.grid("off")
            ax.xaxis.set_visible(False)

        for ax, angle in zip(self.axes, self.angles):
            ax.set_rgrids(range(1, 10), angle=angle, labels='')
            ax.set_ylim(0, 10)
            ax.set_theta_offset(np.deg2rad(rotation))       # by default zero angle points to right, not top
            # ax.spines["polar"].set_visible(False)     # disables the borders around radar

fig = pl.figure(figsize=(7, 7))
categories = [('Height', 0, 10),
              ('Age', 0, 100),
              ('Weight', 12, 33),
              ('BMI', 10, 100),
              ('Body Fat%', 0, 100)]

radar = Radar(fig, categories)
#radar.ax.legend()
pl.title('Sample Radar Template')
pl.show()

0 个答案:

没有答案