在多个轴上具有多个比例尺的雷达图 [英] Radar chart with multiple scales on multiple axes

查看:191
本文介绍了在多个轴上具有多个比例尺的雷达图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用matplotlib在多个轴上绘制具有多个比例的雷达图. 官方API示例在一个轴上仅给出一个比例. (在此示例中,比例为0.2、0.4、0.6、0.8)

I want to plot a radar chart with multiple scales on multiple axes using matplotlib. The official API example gives only one scale on one axis. (Scales are 0.2,0.4,0.6,0.8 in this example)

我想在所有轴上使用不同的比例. (在给定的示例中有9个轴.)

I want different scales on all axes. (There are 9 axes in the given example.)

我在此处.就像我想要的那样,在此示例中有5个轴,并且在所有轴上有5个比例尺.

I found an example of what I am looking for here. There are 5 axes on this example and 5 scales on all axes just like I want.

推荐答案

我认为您可以用多个轴绘制该图,这些线位于第一个轴上,而其他轴仅显示刻度标签.

I think you can plot this with multiple axes, the lines are in the first axe, and other axes only shows ticklabels.

import numpy as np
import pylab as pl

class Radar(object):

    def __init__(self, fig, titles, labels, rect=None):
        if rect is None:
            rect = [0.05, 0.05, 0.95, 0.95]

        self.n = len(titles)
        self.angles = np.arange(90, 90+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]
        self.ax.set_thetagrids(self.angles, labels=titles, fontsize=14)

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

        for ax, angle, label in zip(self.axes, self.angles, labels):
            ax.set_rgrids(range(1, 6), angle=angle, labels=label)
            ax.spines["polar"].set_visible(False)
            ax.set_ylim(0, 5)

    def plot(self, values, *args, **kw):
        angle = np.deg2rad(np.r_[self.angles, self.angles[0]])
        values = np.r_[values, values[0]]
        self.ax.plot(angle, values, *args, **kw)



fig = pl.figure(figsize=(6, 6))

titles = list("ABCDE")

labels = [
    list("abcde"), list("12345"), list("uvwxy"), 
    ["one", "two", "three", "four", "five"],
    list("jklmn")
]

radar = Radar(fig, titles, labels)
radar.plot([1, 3, 2, 5, 4],  "-", lw=2, color="b", alpha=0.4, label="first")
radar.plot([2.3, 2, 3, 3, 2],"-", lw=2, color="r", alpha=0.4, label="second")
radar.plot([3, 4, 3, 4, 2], "-", lw=2, color="g", alpha=0.4, label="third")
radar.ax.legend()

这篇关于在多个轴上具有多个比例尺的雷达图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆