I want to plot a vertical dotted red line in particular point (say 2.2) in xmgrace using script
You can either use an external tool such as pygrace or use grace's built-in batch capabilities. These have been touched upon here on SO before (see, for instance, here or here).
The following script plots a datafile (exp.dat) as empty circles, another data file (line.dat) as a red dotted line and sets the ranges, labels and major ticks of the two axes:
READ NXY "exp.dat"
READ NXY "line.dat"
WORLD XMIN 0
WORLD XMAX 5
WORLD YMIN 1
WORLD YMAX 5
xaxis label "My x label"
xaxis tick major 1
yaxis label "My y label"
yaxis tick major 1
s0 line type 0
s0 symbol 1
s0 symbol size 1.5
s1 linestyle 2
s1 color 2
To generate a vertical red dotted line that passes through 2.2 the contents ofline.dat should be something like
2.2 0
2.2 10000
You can generate such a file in a bash script with the following command:
echo "2.2 0\n2.2 10000" > line.dat
Save the script as mybatch.xmg and call it like this:
xmgrace -batch mybatch.xmg
If you want to directly generate an output you can add this directive:
PRINT TO "myplot.eps"
DEVICE "EPS" OP "level2"
PRINT
which will save your plot as myplot.eps (add -nosafe when calling xmgrace to get rid of the warnings).
Related
I'm doing a gif in gnuplot, and I have my data separated in blocks. I need the points to be white except from just the first row of every data block, which would be an orange point.
Currently my code is:
#...
do for [i=0:int(STATS_blocks-1)]{
plot "positions.txt" index i pt 7 ps 0.5 lc 'white' title "t = ".((i+1)*200)." Myr"
}
As you can see, this plots every data point white, including the first row.
Edited to show variable pointsize also
If I understand your data format correctly:
set linetype 11 lc "orange"
set linetype 12 lc "white"
set style data points
do for [i=0:N] {
plot "positions.txt" index i using 1:2:(column(0)>0 ? 0.5 : 2.0):(column(0)>0 ? 12 : 11) pt 7 ps variable lc variable
}
Variable color (if used) is always taken from the very last using column. Other variable properties work back from there.
Very simple stuff. I want a function, say function f, to be plotted with a particular color. I also want a piece of label saying "function f color" which is also displayed in that color.
I am trying this so far:
set style line 1 lw 3 lc 1
set label "AC" at 0, 70 textcolor 1
but apparently the "lc" and "textcolor" follows different specs, and it complains:
"trolo4.pl", line 8: colorspec option not recognized
any help would be great!
Try this instead:
set label "AC" at 0, 70 textcolor linetype 1
or
set label "AC" at 0, 70 textcolor linespec 1
Read the manual in gnuplot> help label to learn more.
The answer by #holygeek works fine. Coming from python, I find that it is often nice to be a little more explicit.
set style line 1 lw 1 lc rgb "red"
set label "AC" at 0, 70 tc rgb "red"
Note that the set of color names recognized by your gnuplot is system dependent (see show colornames for a complete list). To achieve complete system independence, you can use the #RRGGBB version. e.g. red is '#ff0000, green is #00ff00 and blue is #0000ff. of course, you can make up all sorts of interesting colors (again, see show colornames for a list of pre-defined colors and their equivalent #.....)
for more info, also see help colorspec
I have a data file consisting of 2 columns with a name and value in it.
foo 0.1
bar 0.2
fff 0.4
bbb 0.7
I want to plot this and annotate the text entry next to the data point.
I tried
plot 'file' using 1:2 with labels
but it didn't work. I guess the proble is that I have to rely on gnuplot using only the second column for y and equally spacing the x axis.
You can do something like
plot 'file' using 0:2 title 'title', \
'' using 0:2:1 with labels offset 0,char 1
This will first plot the data normally, then plot with labels on top, offset up by one character. The 0 column is a dummy column which gives an index to the data--0 for the first data point, 1 for the second, etc.
Another alternative would be to plot using a histogram.
I have lots of files to generate a plot for and therefore wrote a little script for gnuplot.
I want to add additional information with a label underneath the graph but my label is not displayed on the generated image.
Anyone gut an idea?
load.plt:
# template.gnuplot
set terminal png
filename = "results-05112012-".i.".dat"
plotfile = "results-05112012-".i.".png"
print filename." ".plotfile
set grid
set title "EER""
set output plotfile
set label "m = 20" at 0, 3 front tc rgb "#ffffff"
plot[0.35:0.75][0:100] filename using 1:6 title "FAR" w lp, filename using 1:7 title "FRR" w lp
unset output
unset label
i=i+1
if(i <= n) reread
I can see two reasons why the label might not appear. One is that the label is at the point (0,3) which is not within the plot region [0.35:0.75][0:100]. The other is that the label is white in color (#ffffff).
I want to create a histogram of a file that contains :
1 144 12.54
2 564 02.34
3 231 01.23
4 452 07.12
and what I use for that purpose in my script is :
gnuplot << EOF
set terminal gif
set terminal postscript eps color enhanced
set output "diagramma";
set title 'Diagramma'
set key off
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth 0.9
set autoscale
set xlabel "May"
plot 'finalsumfile' using 1:2 with histogram, 'finalsumfile' using 1:3 with histogram
EOF
So I want the first column as x coordinate and the second and third columns as y.
BUT when I run my script occurs this error:
line 0: Too many columns in using specification
What am I doing wrong?
try:
plot 'finalsumfile' using 2:xticlabels(1) with histogram
Histograms typically only take 1 column of data, which the "x-value" being implicitly incremented by one each time starting from 0. To set explicit x labels, you need to use xticlabels which takes the string in the given column and uses that as the label.