2012-10-03 5 views
5

Ich möchte ein Spider (alias Radar/Stern) Plot mit Gnuplot produzieren, wo verschiedene Achsen unabhängige Skalen haben. Ich kann mit OriginPro (kommerziell) ein solches Diagramm erstellen, aber mit Gnuplot kann ich nur ein Radarplot mit einheitlichem Maßstab erstellen.Wie erstelle ich ein Spider-Plot in Gnuplot?

Die (csv-Datei)-Datensatz sieht wie folgt aus (erste Zeile Spaltenbeschriftungen ist):

# 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 

und die Handlung ich suche ist diese: https://www.dropbox.com/s/uvqubzqvm6puhb8/spider.pdf - Wie Sie jede Achse steht sehen für ein anderes Attribut, und hat eine eigene Skala.

Ich denke, die Gnuplot Startcode ist:

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

Aber ich weiß nicht, wie es weitergeht. Irgendwelche Vorschläge?

Antwort

1

Die Antwort von @george half mir herauszufinden, wie der Datensatz neu zu ordnen, um daraus die entsprechenden Attributdaten zu holen. Weil ich auch nach verschiedenen Bereichsskalen für die verschiedenen Spinnenachsen suchte, dachte ich zusätzlich zu @ George's Vorschlag, dass eine achsspezifische Normalisierung auf den gemeinsamen [0: 1] Bereich das Problem gelöst hätte. Die Hauptänderung bezieht sich dann auf das Feld using des Befehls plot.

Der Code ist ziemlich lang, ich bin mir sicher, dass es optimiert werden könnte. Es könnte auch in ein Skript oder einen einfachen C-Code zusammengeführt werden, damit der Benutzer die Anzahl der Achsen (Anzahl der Attribute) und die verschiedenen Bereiche (Min, Max) für jede spezifische Achse bestimmen kann.

Das folgende Beispiel bezieht sich auf 5 Attribute zum Vergleich von 2 Produkten. Hier ist die 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 
+0

Überprüfen Sie dieses [http://stackoverflow.com/questions/30649826/how-to-highlight-regions-of-plot-with-gnuplot/30684027#30684027], es ist viel einfacher, die Anzahl der Sterne usw. anzupassen – Karl

3

hier ist ein Hack Versuch ..

set nokey 
set polar 
set grid polar 
set angles degrees 
set size square 
set style data lines 
a1=0 
a2=30 
a3=100 
a4=200 
a5=300 
set arrow nohead from 0,0 to first 10*cos(a1) , 10*sin(a1) 
set arrow nohead from 0,0 to first 10*cos(a2) , 10*sin(a2) 
set arrow nohead from 0,0 to first 10*cos(a3) , 10*sin(a3) 
set arrow nohead from 0,0 to first 10*cos(a4) , 10*sin(a4) 
set arrow nohead from 0,0 to first 10*cos(a5) , 10*sin(a5) 
set xrange [-10:10] 
set yrange [-10:10] 
plot '-' using ($1==1?a1:($1==2?a2:($1==3?a3:($1==4?a4:($1==5?a5:$1))))):2 lt 2 
1 4 
2 8 
3 6 
4 9 
5 5 
1 4 
+0

Danke @george für Ihre Antwort! Sehr geschätzt. Die logische Funktion im using-Feld für den Plot-Befehl hat mir sehr geholfen, das Problem zu lösen. – CarloAlberto