2016-12-01 7 views
0

this question Folgen, habe ich jetzt eine Heatmap mit benutzerdefinierten colorbar. Jetzt muss ich Konturlinien mit Etiketten versehen. Ich habe die Konturlinien erstellt, aber ich kann nicht herausfinden, wie ich sie anordnen soll.Konturlinien mit Etiketten in Heatmap mit GNUplot

Dies ist die Handlung ich derzeit haben:

enter image description here

Code, um das Grundstück zu generieren:

reset 
#Function map values on desired ranges. The values set to 90,95,99 are for later labelling 
step(x) = (x < 20.0 ? 0 : (x < 50.0 ? 10 : (x < 75.0 ? 20 : (x < 90.0 ? 80 : (x < 95.0 ? 90 : (x < 97.5 ? 95 : (x < 99.0 ? 97 : (x < 99.5 ? 99 : (x < 99.9 ? 100 : 101))))))))) 

# enable 3D data read from a scattered data set in file 
#71,46,10 are the number of different values for each axis X,Y,Z in "HeatMap_Test.txt" data file 
#If values of dgrid3d are not set accordingly, weird contour values will be generated 
set dgrid3d 71,46,10 
set contour base # enable contour drawing 
set cntrlabel font ",7" 
set view 0,0 # if you want to see the graph from above (2D plot) 
unset surface # do not plot the surface, only the contour 
set cntrparam levels discrete 90,95,99 #set contours only on values 90,95 and 99 
set table "contours.dat" #Name of the output file to write the table 
splot "HeatMap_Test.txt" u 2:1:(step($3)) with lines notitle 
unset table #Write table to file 


reset 
#Map the Z values to desired ranges 
step(x) = (x < 20.0 ? 0 : (x < 50.0 ? 1 : (x < 75.0 ? 2 : (x < 90.0 ? 3 : (x < 95.0 ? 4 : (x < 97.5 ? 5 : (x < 99.0 ? 6 : (x < 99.5 ? 7 : (x < 99.9 ? 8 : 9))))))))) 

set palette maxcolors 10 
set palette defined (0 "#333399", 1 "#3333f7", 2 "#3373ff", 3 "#33c6ff", 4 "#5affd2", 5 "#9cff8f", 6 "#dfff4c", 7 "#ffc733", 8 "#ff7a33", 9 "#e53333") 

set cbrange [-0.5:9.5] 
set cbtics nomirror 
set cbtics (">99.9" 9, ">99.5" 8, ">99.0" 7, ">97.5" 6, ">95.0" 5, ">90.0" 4, ">75.0" 3, ">50.0" 2, ">20.0" 1, ">10.0" 0) 

set xrange [-30:40] 
set yrange [ 25:70] 
set xtics 5 
set ytics 5 
#set title "                                  %" 

set grid front linetype -1 
set grid xtics lt 0 lw 1 lc rgb "#000000" 
set grid ytics lt 0 lw 1 lc rgb "#000000" 

plot "HeatMap_Test.txt" u 2:1:(step($3)) notitle pt 5 ps 2 lc palette, "world_10m.txt" notitle with lines ls 1 lc -1, "contours.dat" u 1:2 w l lw 2 lc 0 notitle 

Hier sind die Datendateien: HeatMap_Test.txt, world_10m.txt

Der Code funktioniert in GNUplot 4,6 und 5 (ich unter Linux arbeite)

Um die Handlung ich will, ich habe noch drei Dinge zu tun zu bekommen:

1) Beschriften Sie die Höhenlinien (mit 99, 95 und 90 von der inneren zur äußeren Linien)

2) Machen Sie den Grenzlinien passen die Handlung (in der Figur die Heatmap über die Grenzen geht)

3) einen Titel Put (in diesem Fall ein einzelnes ‚%‘) nur auf dem colorbar. Eine schmutzige Art und Weise dies zu tun ist, einen normalen Titel zu setzen und Leerzeichen zu setzen (es gibt eine kommentierte Zeile im Code, um das zu tun), aber ich denke, dass es etwas besseres geben muss.

Meine Idee, die Form von Markierungen wie in diesem Bild ist:

enter image description here

Vielen Dank für Ihre Hilfe

Antwort

0

Ich habe es endlich, dank der Antwort von @maij, mit der link er zur Verfügung gestellt.

Mit der Ausgabe Nummer , I @maij Linie mit diesem Parameter verwendet:

set cblabel "%" norotate offset -8, 12 

Mit der Ausgabe Nummer , wenn die Heatmap Plotten, hatte ich von

plot "HeatMap_Test.txt" u 2:1:(step($3)) notitle pt 5 ps 2 lc palette 
zu ändern

zu

plot "HeatMap_Test.txt" u 2:1:(step($3)) with image 

Last, mit Ausgabenummer , die Etikett in den Konturlinien zu setzen, ich einen externen awk-Skript in den gleichen link wie bisher nutzen musste. Ich nannte das Skript draw_contourlines_label.sh, und der Inhalt des Skripts ist:

#!/bin/bash 

awk -v d=$2 -v w=$3 -v os=$4 'function abs(x) { return (x>=0?x:-x) } 
    { 
     if($0~/# Contour/) nr=0 
     if(nr==int(os+w/2) && d==0) {a[i]=$1; b[i]=$2; c[i]=$3;} 
     if(nr==int(os+w/2)-1 && d==0) {i++; x = $1; y = $2;} 
     if(nr==int(os+w/2)+1 && d==0) r[i]= 180.0*atan2(y-$2, x-$1)/3.14 
     if(abs(nr-os-w/2)>w/2 && d==1) print $0 
     nr++ 
    } 
    END { if(d==0) { 
      for(j=1;j<=i;j++) 
       printf "set label %d \"%g\" at %g, %g centre front rotate by %d\n", j, c[j], a[j], b[j], r[j] 
      } 
    }' "$1" 

Dieses Skript hat die folgenden Parameter:

# 1 -> mit den Konturdaten erzeugt durch GNUplot Datei

# 2 -> Flagge. Wenn es "0" ist, wird ein Skript für GNUplot gedruckt, um die Beschriftungen im Diagramm hinzuzufügen.Wenn es ‚1‘ ist, nimmt die Punkte der Konturlinien aus, so dass die Linien der Kontur-Plots gehen nicht über das Etikett

# 3 -> Anzahl der Räume für die Formatierung des Etiketts

# 4 - > Offset die weißen Räume für die Etiketten zu bewegen (so sie nicht zentriert sind)

Mein Ergebnis wxt Terminal ist:

Das Ergebnis ist:

enter image description here

Der Code um den Plot zu erzeugen ist:

reset 
#Function map values on desired ranges. The values set to 90,95,99 are for later labelling 
step90(x) = (x < 20.0 ? 0 : (x < 50.0 ? 10 : (x < 75.0 ? 20 : (x < 90.0 ? 80 : (x < 95.0 ? 90 : (x < 97.5 ? 95 : (x < 99.0 ? 97 : (x < 99.5 ? 99 : (x < 99.9 ? 100 : 101))))))))) 
# enable 3D data read from a scattered data set in file 
#71,46,10 are the number of different values for each axis X,Y,Z in "HeatMap_Test.txt" data file 
#If values of dgrid3d are not set accordingly, weird contour values will be generated 
set dgrid3d 71,46,10 
set contour base # enable contour drawing 
set view 0,0 # if you want to see the graph from above (2D plot) 
unset surface # do not plot the surface, only the contour 
set cntrparam levels discrete 90,95,99 #set contours only on values 90,95 and 99 
set table "contours.dat" #Name of the output file to write the table 
splot "HeatMap_Test.txt" u 2:1:(step90($3)) notitle    
unset table #Write table to file 

reset 
#Map the Z values to desired ranges 
step(x) = (x < 20.0 ? 0 : (x < 50.0 ? 1 : (x < 75.0 ? 2 : (x < 90.0 ? 3 : (x < 95.0 ? 4 : (x < 97.5 ? 5 : (x < 99.0 ? 6 : (x < 99.5 ? 7 : (x < 99.9 ? 8 : 9))))))))) 

set palette maxcolors 10 
set palette defined (0 "#333399", 1 "#3333f7", 2 "#3373ff", 3 "#33c6ff", 4 "#5affd2", 5 "#9cff8f", 6 "#dfff4c", 7 "#ffc733", 8 "#ff7a33", 9 "#e53333") 

set cbrange [-0.5:9.5] 
set cbtics nomirror 
set cbtics (">99.9" 9, ">99.5" 8, ">99.0" 7, ">97.5" 6, ">95.0" 5, ">90.0" 4, ">75.0" 3, ">50.0" 2, ">20.0" 1, ">10.0" 0) 
set cblabel "%" norotate offset -8, 12 

set xrange [-30:40] 
set yrange [ 25:70] 
set xtics 5 
set ytics 5 

set grid front linetype -1 
set grid xtics lt 0 lw 1 lc rgb "#000000" 
set grid ytics lt 0 lw 1 lc rgb "#000000" 

load "<./draw_contourlines_label.sh contours.dat 0 4 0" 
plot "HeatMap_Test.txt" u 2:1:(step($3)) with image, "world_10m.txt" notitle with lines ls 1 lc -1, "<./draw_contourlines_label.sh contours.dat 1 3 0" u 1:2 w l lw 2 lc 0 notitle 

HINWEIS: Wenn die Datei „contours.dat“ mit GNUplot 4.6.4 berechnet wird, die Etiketten auf die gleiche Art und Weise nicht erscheinen. Sobald die Datei berechnet ist, wird in Version 4.6+ dieselbe Grafik angezeigt.

Wir können auch verwenden @maij Ansatz mit Splot-Funktion. Um dies zu tun, müssen wir zuerst die Schrittfunktion ändern, wie er sagte, weil es sonst merkwürdige Linien erzeugt. Ich benannte die Funktion step3D, aber es ist genau @maij oben gepostet:

step(x) = (x < 20.0 ? 0 : \ 
      (x < 50.0 ? 10 : \ 
      (x < 75.0 ? 20 : \ 
      (x < 90.0 ? 80 : \ 
      (x < 95.0 ? 89.999 : \ 
      (x < 97.5 ? 94.999 : \ 
      (x < 99.0 ? 97 : \ 
      (x < 99.5 ? 98.999 : \ 
      (x < 99.9 ? 100 : 101))))))))) 

Mit splot, gibt es auch die Notwendigkeit, die Eingabedatei in Blöcke zu formatieren. Ich habe mit diesem einfachen awk-Skript, das direkt in dem splot Befehl gesetzt werden kann:

awk 'NF>=1 && $1!~/#/ && $1!=prev {print \"\"} {prev=$1;print}' HeatMap_Test.txt 

In GNUplot 5+, beim Plotten der colobar Prozent erschienen Halb zerschnitt und die x- und y-Etikett wurden auch getrennt, so musste ich sie manuell optimieren, um den Bildschirm zu passen mit diesen Befehlen:

set rmargin at screen 0.8 
set lmargin at screen 0.08 
set tmargin at screen 0.95 
set xtics offset 0, screen 0.036 
set ytics offset screen 0.008, 0 

die Konturlinien werden mit dem gleichen Befehl aufgetragen, so das Ergebnis, das wir bekommen, ist ähnlich (nur die Konturlinien auf Grund der etwas ändern Bereiche):

enter image description here

Der Code um den Plot zu erzeugen ist:

reset 
#Function map values on desired ranges. The values set to 90,95,99 are for later labelling 
step3D(x) = (x < 20.0 ? 0 : (x < 50.0 ? 10 : (x < 75.0 ? 20 : (x < 90.0 ? 80 : (x < 95.0 ? 89.999 : (x < 97.5 ? 94.999 : (x < 99.0 ? 97 : (x < 99.5 ? 98.999 : (x < 99.9 ? 100 : 101))))))))) 
# enable 3D data read from a scattered data set in file 
#71,46,10 are the number of different values for each axis X,Y,Z in "HeatMap_Test.txt" data file 
#If values of dgrid3d are not set accordingly, weird contour values will be generated 
set dgrid3d 71,46,10 
set contour base # enable contour drawing 
set view 0,0 # if you want to see the graph from above (2D plot) 
unset surface # do not plot the surface, only the contour 
set cntrparam levels discrete 90,95,99 #set contours only on values 90,95 and 99 
set table "contours.dat" #Name of the output file to write the table 
splot "HeatMap_Test.txt" u 2:1:(step3D($3)) notitle 
unset table #Write table to file 


reset 
#Map the Z values to desired ranges 
step(x) = (x < 20.0 ? 0 : (x < 50.0 ? 1 : (x < 75.0 ? 2 : (x < 90.0 ? 3 : (x < 95.0 ? 4 : (x < 97.5 ? 5 : (x < 99.0 ? 6 : (x < 99.5 ? 7 : (x < 99.9 ? 8 : 9))))))))) 

set palette maxcolors 10 
set palette defined (0 "#333399", 1 "#3333f7", 2 "#3373ff", 3 "#33c6ff", 4 "#5affd2", 5 "#9cff8f", 6 "#dfff4c", 7 "#ffc733", 8 "#ff7a33", 9 "#e53333") 

set cbrange [-0.5:9.5] 
set cbtics nomirror 
set cbtics (">99.9" 9, ">99.5" 8, ">99.0" 7, ">97.5" 6, ">95.0" 5, ">90.0" 4, ">75.0" 3, ">50.0" 2, ">20.0" 1, ">10.0" 0) 
set cblabel "%" norotate offset -8, 11.5 

set xrange [-30:40] 
set yrange [ 25:70] 
set xtics 5 
set ytics 5 

set grid front linetype -1 
set grid xtics lt 0 lw 1 lc rgb "#000000" 
set grid ytics lt 0 lw 1 lc rgb "#000000" 

set rmargin at screen 0.8 
set lmargin at screen 0.08 
set tmargin at screen 0.95 
set xtics offset 0, screen 0.036 
set ytics offset screen 0.008, 0 
set pm3d explicit 
set view map 
load "<./draw_contourlines_label.sh contours.dat 0 4 0" 
splot "< awk 'NF>=1 && $1!~/#/ && $1!=prev {print \"\"} {prev=$1;print}' HeatMap_Test.txt" u 2:1:(0):(step($3)) notitle w pm3d lc palette ,"world_10m.txt" u 1:2:(0) notitle with lines ls 1 lc rgb "#ffffff", "<./draw_contourlines_label.sh contours.dat 1 3 0" u 1:2:(0) w l lw 2 lc rgb "#000000" notitle 

HINWEIS: Wenn Sie ein Windows-Benutzer sind, können Sie diese Handlung tun auch die GNUplot Version des Cygwin mit

1

der mit Nummer 3 Lassen Sie beginnen: Ein Titel für das colorbar.

Sie wollen die cblabel auf dem colorbar einzustellen. Während ich glaube nicht, dass dies automatisch durchgeführt werden kann, können Sie ein offset x,y wie folgt verwenden:

set cblabel "%" norotate offset -6, 9 

Noch ein Hack, aber ich denke, es ist besser, als der Titel zu mißbrauchen.

Jetzt Nummer : Machen Sie die Grenzen passend zum Plot.

Der Grund für die über die Grenze gehen die (implizite) Befehl plot with points pointsize 2. Die Punkte, die gerade am Rand gezeichnet werden, überlappen sich. Ich würde die Punkte mit einem splot pm3d wie diese ersetzen vorschlagen:

set pm3d explicit 
set view map 
splot "HeatMap_Test_2.txt" u 2:1:(0):(step($3)) notitle w pm3d lc palette , \ 
     "world_10m.txt" u 1:2:(0) notitle with lines ls 1 lc rgb "#ffffff" , \ 
     "contours.dat" u 1:2:(0) w l lw 2 lc rgb "#000000" notitle 

Um diese 3D splot zu arbeiten, habe ich folgendes:

  • fügen Sie eine Dummy-z-Säule, die Anzahl (0)
  • Format "HeadMap_test.txt“in Blöcke, die eine Leerzeile nach jeder Breite Scan einzufügen bedeutet

aus:

... 
25.00 38.00 15.9 
25.00 39.00 5.3 
25.00 40.00 1.6 
26.00 -30.00 0.0 
26.00 -29.00 0.3 
26.00 -28.00 0.7 
... 

zu:

... 
25.00 38.00 15.9 
25.00 39.00 5.3 
25.00 40.00 1.6 

26.00 -30.00 0.0 
26.00 -29.00 0.3 
26.00 -28.00 0.7 
... 
  • und ich hatte die erste Stufe einzustellen Funktion, um die Konturen ein wenig zu finden, habe ich die Werte der Schritte bei 90, 95 und 99 etwas reduziert

So:

step(x) = (x < 20.0 ? 0 : \ 
      (x < 50.0 ? 10 : \ 
      (x < 75.0 ? 20 : \ 
      (x < 90.0 ? 80 : \ 
      (x < 95.0 ? 89.999 : \ 
      (x < 97.5 ? 94.999 : \ 
      (x < 99.0 ? 97 : \ 
      (x < 99.5 ? 98.999 : \ 
      (x < 99.9 ? 100 : 101))))))))) 

Jetzt, mit pngcairo Terminal und Gnuplot 4.6, sollten wir hier angekommen sind:

picture fits to border

Und Nummer : Beschriften Sie die Höhenlinien

Ich habe es nicht versucht, aber vielleicht this post kann Ihnen helfen.

+0

, um die leeren Zeilen hinzufügen die Dateien, habe ich dieses Skript erstellt: '" < awk 'NF> = 1 && $ 1! ~/#/&& $ 1! = vorherige {print \ "} {prev = $ 1; print} 'HeatMap_Test.txt'' was sein kann direkt in GNUplot einfügen. Ich werde sehen, ob ich einen Weg finde, die Etiketten zu setzen. Danke. – AwkMan

Verwandte Themen