Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 多轴多标度雷达图_Python_Matplotlib_Plot - Fatal编程技术网

Python 多轴多标度雷达图

Python 多轴多标度雷达图,python,matplotlib,plot,Python,Matplotlib,Plot,我想使用matplotlib在多个轴上绘制具有多个刻度的雷达图。在一个轴上只给出一个刻度。(本例中的刻度为0.2,0.4,0.6,0.8) 我希望所有轴上都有不同的刻度。(给定示例中有9个轴。) 我找到了一个我正在寻找的例子。本例中有5个轴,所有轴上都有5个比例,就像我想要的一样。我想你可以用多个轴来绘制,线在第一个轴上,其他轴只显示标签 import numpy as np import pylab as pl class Radar(object): def __init__(s

我想使用
matplotlib
在多个轴上绘制具有多个刻度的雷达图。在一个轴上只给出一个刻度。(本例中的刻度为0.2,0.4,0.6,0.8)

我希望所有轴上都有不同的刻度。(给定示例中有9个轴。)


我找到了一个我正在寻找的例子。本例中有5个轴,所有轴上都有5个比例,就像我想要的一样。

我想你可以用多个轴来绘制,线在第一个轴上,其他轴只显示标签

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()

我遇到了这个错误-“未定义全局名称“angles”。您可以添加您所做的更改吗。@Bharathi,错误已修复。如果您想查看上面代码的某些输出,您必须在末尾添加至少fig.savefig(“somename.png”)。此外,我在使用上面的示例时遇到了一个问题,axis的角度大于360度。即标题“A”的虚线缺失。我解决了这个问题,在“self.angles=np.arange(90,90+360,360.0/self.n)”之后添加了一个新行“self.angles=[a%360代表一个in-self.angles]”。环境:Python 2.7.12::Anaconda 4.2.0(64位)、matplotlib(1.5.3)、numpy(1.11.1)。无论如何,谢谢你的工作;-)与@keocra有相同的问题,可能是库被更新了,现在表现不同了。以下是我对12轴雷达图的工作解决方案: