2017-05-12 2 views
0

Ich versuche, in der Mitte der Boxen von Plot (Plotten durch gnu Plot) zu schreiben, kann aber nicht auf elegante Weise finden. Es ist mühsam, die Mittelpunkte aller Boxen manuell zu finden. Bitte führe mich, um es herauszufinden. Here at the position of circles, I want to add some text, verticallyGnuPlot: Schreibe etwas Text in der Mitte der Boxen

+1

Verwendung beispiel 'Grundstück mit labels'. – Christoph

Antwort

1

Als @Christoph in den Kommentaren erwähnt, plot ... w labels ist eine der Optionen. Die einzige zusätzliche "Zutat" besteht darin, die Position der Etiketten zu berechnen. Man könnte zum Beispiel gehen Sie wie:

set terminal pngcairo 
set output 'fig.png' 

fName='test.dat' 

bw = 0.9 

yMin = 50 
yMax = 130 

xMin = 2 
xMax = 15 

set boxwidth bw 

set xr [xMin - bw/2:xMax + bw/2] 
set yr [yMin:yMax] 

#scale 0 makes sure that the tic marks don't "show up" 
set format x "1 %.0f" 
set xtics 2,1,15 rotate by -15 scale 0 

set ytics 50,10,130 scale 0 

set ylabel "TODO" 
set xlabel "TODO" 

set key top right 

#place the labels in the "middle" with respect to the 
#minimum on the y-axis 
p \ 
    100 t "Todo" lc rgb "black" dt 3, \ 
    fName u 1:2 w boxes t "TODO" lc rgb "black", \ 
    fName u 1:(($2-yMin)/2+yMin):(sprintf("%.0f", $2)) w labels t '' tc rgb 'dark-red' 

Dies erzeugt: enter image description here

Datendatei unter der Annahme test.dat als:

2 100 
3 75 
4 74 
5 76 
6 74 
7 78 
8 92 
9 98 
10 75 
11 105 
12 118 
13 120 
14 122 
15 122