如何在Gnuplot中创建蜘蛛图? [英] How to Create a Spider Plot in Gnuplot?

查看:87
本文介绍了如何在Gnuplot中创建蜘蛛图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Gnuplot生成一个蜘蛛图(又名雷达/星图),其中不同的轴具有独立的比例尺.我可以使用OriginPro(商业版)生成这样的图,但是使用Gnuplot我只能设置具有统一比例的雷达图.

I would like to produce a spider (aka radar/star) plot using Gnuplot where different axes have independent scales. I am able to produce such a plot using OriginPro (commercial), but with Gnuplot I am only able to set a radar plot with uniform scale.

(csv文件)数据集如下所示(第一行是列标签):

The (csv file) dataset looks like the following (first row is column labels):

# FEATURE, Product_A, Product_B, Product_C, Product_D
attribute_1, 2, 10, 7, 3.5
attribute_2, 1, 0.5, 3,4
attribute_3, 37, 58, 49, 72
attribute_4, 1985, 1992, 2006, 2010
attribute_5, 0.1, 0.5, 0.3, 0.8

我正在寻找的情节就是这个: https://www. dropbox.com/s/uvqubzqvm6puhb8/spider.pdf - 如您所见,每个轴代表一个不同的属性,并具有自己的比例尺.

and the plot I am looking for is this one: https://www.dropbox.com/s/uvqubzqvm6puhb8/spider.pdf - As you can see each axis stands for a different attribute, and has its own scale.

我想Gnuplot的起始代码是:

I guess the Gnuplot starting code is:

set polar
set grid polar
set angles degrees
set size square
set style data filledcurves

但是我不知道如何进行.有什么建议吗?

But I don't know how to proceed. Any suggestions?

推荐答案

@george的回答帮助我弄清楚了如何重新排列数据集,以便从中选择相应的属性数据. 因为除了@george的建议外,我还在寻找用于不同蜘蛛轴的不同范围比例,所以我认为将特定于轴的归一化到通用[0:1]范围可以解决该问题.然后,主要修改与plot命令的using字段相关.

The answer by @george helped me figure out how to rearrange the dataset, in order to pick from it the corresponding attribute data. Because I was also looking for different range scales for the different spider axes, in addition to @george's suggestion, I thought that an axis-specific normalisation to the common [0:1] range, would have the problem solved. The main modification is then related to the using field of the plot command.

代码相当长,我确定可以对其进行优化.也可以将其合并到脚本或简单的C代码中,以使用户确定轴数(属性数)以及每个特定轴的不同范围(最小,最大).

The code is fairly lengthy, I'm sure it could be optimised. It could also be merged into a script or a simple C code, in order to let the user decide the number of axes (number of attributes), and the different ranges (min, max) for each specific axis.

以下示例针对比较2个产品的5个属性.此处显示了绘制结果图像:

The following example is for 5 attributes comparing 2 products. Here is shown the plot result image:

set nokey
set polar
set angles degrees
npoints = 5
a1 = 360/npoints*1
a2= 360/npoints*2
a3= 360/npoints*3
a4= 360/npoints*4
a5= 360/npoints*5
set grid polar 360.
set size square
set style data lines
unset border
set arrow nohead from 0,0 to first 1*cos(a1) , 1*sin(a1)
set arrow nohead from 0,0 to first 1*cos(a2) , 1*sin(a2)
set arrow nohead from 0,0 to first 1*cos(a3) , 1*sin(a3)
set arrow nohead from 0,0 to first 1*cos(a4) , 1*sin(a4)
set arrow nohead from 0,0 to first 1*cos(a5) , 1*sin(a5)
a1_max = 10
a2_max = 5
a3_max = 100
a4_max = 2020
a5_max = 1
a1_min = 0
a2_min = 0
a3_min = 50
a4_min = 1980
a5_min = 0
set label "(0:10)" at cos(a1),sin(a1) center offset char 1,1
set label "(0:5)" at cos(a2),sin(a2) center offset char -1,1
set label "(50:100)" at cos(a3),sin(a3) center offset char -1,-1
set label "(1980:2020)" at cos(a4),sin(a4) center offset char 0,-1
set label "(0:1)" at cos(a5),sin(a5) center offset char 3,0
set xrange [-1:1]
set yrange [-1:1]
unset xtics
unset ytics
set rrange [0:1]
set rtics (""0,""0.25,""0.5,""0.75,""1)

plot '-' using ($1==1?a1:($1==2?a2:($1==3?a3:($1==4?a4:($1==5?a5:$1))))):($1==1?(($2-a1_min)/(a1_max-a1_min)):($1==2?(($2-a2_min)/(a2_max-a2_min)):($1==3?(($2-a3_min)/(a3_max-a3_min)):($1==4?(($2-a4_min)/(a4_max-a4_min)):($1==5?(($2-a5_min)/(a5_max-a5_min)):$1))))) w l
1 8
2 3
3 67
4 2000
5 0.2
1 8

plot '-' using ($1==1?a1:($1==2?a2:($1==3?a3:($1==4?a4:($1==5?a5:$1))))):($1==1?(($2-a1_min)/(a1_max-a1_min)):($1==2?(($2-a2_min)/(a2_max-a2_min)):($1==3?(($2-a3_min)/(a3_max-a3_min)):($1==4?(($2-a4_min)/(a4_max-a4_min)):($1==5?(($2-a5_min)/(a5_max-a5_min)):$1))))) w l
1 6
2 1.5
3 85
4 2010
5 0.5
1 6

这篇关于如何在Gnuplot中创建蜘蛛图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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