Adding a string to a gnuplot autotitle - string

I am using the gnuplot scrip command set key autotitle columnhead to make the lables for my data. The only issue is, the column head data is numeric and so it doesnt really mean much on its own.
Is there a way to add a fixed string to the autotitle, eg "Year " + columnhead, or alternatively, give my key a title?

String concatenation using . operator with columnhead() works in gnuplot v4.6 (documentation):
set terminal pngcairo enhanced truecolor size 480,320 fontscale 0.8
set output 'autotitle.png'
set key left Left
plot for [i=2:4] 'data.txt' u 1:i w l t 'f(x) = '.columnhead(i)
Also, yes, you can set a title for the key instead, like this: set key title 'f(x)'.
Input file data.txt used in this example:
x 100x x^3 2^x
1 100 1 2
2 200 8 4
3 300 27 8
4 400 64 16
5 500 125 32
6 600 216 64
7 700 343 128
8 800 512 256
9 900 729 512
10 1000 1000 1024

Related

gnuplot multiple axes (x1y1, x1y2) to plot data from a single file

I am trying to use multiple axes (2 axes x1y1, x1y2) to plot data from a single file. I am having trouble in get the right figure. Any help is greatly appreciated. Thanks.
I am parametrising my gnu plots.
gnuplot -e "datafile='output';
mytitle = 'Latency Vs Packet number (Arrival Rate = 0.3125 pkts/sec, Schedule Rate = 2 pkts/sec) [ES]';
outputname='latvspno_1024.jpg';
x_label='Packet number';
y_label='Packet Latency (Last bit entering to exiting)';
y2_label='Queue Size (in bytes)';
parameter1='Packet Latency';
parameter2='Queue Size'
" scriptv2.plt
This is my scriptv2.plt script that I use for plotting.
set autoscale # scale axes automatically
unset log # remove any log-scaling
unset label # remove any previous labels
set xtic auto # set xtics automatically
set ytic nomirror # set ytics automatically
set y2tic # set ytics automatically
set nokey
set grid
#set term postscript eps#output terminal and file
#set output "qsim.ps"
#set terminal png
#set terminal jpeg medium size 640,480
set terminal jpeg large size 800,600
set output outputname
#set title "Plot of Queue length Vs time (based on config)"
set title mytitle
set xlabel x_label
set ylabel y_label
set y2label y2_label
set key left top
plot datafile axes x1y1 using 1:5 title parameter1 with linespoints pt 7 ps 2,\
datafile axes x1y2 using 1:6 title parameter2 with linespoints pt 7 ps 2
The following is the contents of my datafile (called output)
0 128 0.4 1.4 1 0 256
1 128 0.8 2.4 1.6 128 512
2 128 1.2 3.4 2.2 256 640
3 128 1.6 4.4 2.8 256 896
4 128 2 5.4 3.4 384 1024
5 128 2.4 6.4 4 512 1152
6 128 2.8 7.4 4.6 512 1408
7 128 3.2 8.4 5.2 640 1536
8 128 3.6 9.4 5.8 640 1792
9 128 4 10.4 6.4 768 1792
10 128 4.4 11.4 7 896 1792
I just misplaced the axes position.
plot datafile using 1:5 axes x1y1 title parameter1 with linespoints pt 7 ps 2,\
datafile using 1:6 axes x1y2title parameter2 with linespoints pt 7 ps 2

gnuplot splot approximation or interpolation?

I'm rendering heat map using gnuplot splot with pm3d using next script
set view map
set dgrid3d
set pm3d interpolate 20,20
set palette defined(\
0 '#00dc00',\
3640 '#00ff00',\
32767 '#c8ff00',\
61894 '#ff8000',\
65535 '#ff7000')
splot "d:/source.dat" using 1:2:3 with pm3d
"source.dat" file contains next values
0 0 36
1 0 36
2 0 36
0 1 36
1 1 36
2 1 36
0 2 36
1 2 36.9
2 2 36
Gnuplot produced next image
But I'm not understand why I have red color in top center point which is equals to 36.6 temperature according to the pallete. In data file I have 36.9 instead of that. It seems to me that gnuplot approximated this value. How I could configure in to interpolate all points?

Specific gnuplot by data grouping

I'm new in gnuplot and sorry that my problem formulation might be unprecise, but I don't know how to find the tools/commnds needed to solve my problem. The code for plotting I would like to integrate in my bash file.
I have a data set like:
285 1 50 7.35092
265 1 50 7.35092
259 1 50 7.35092
258 1 50 7.35092
264 1 50 7.35092
491 5 50 33.97
488 5 50 33.97
495 5 50 33.97
492 5 50 25.1649
495 5 50 33.0725
500 5 50 13.6176
507 5 50 32.2502
489 5 50 33.0725
494 5 50 33.97
491 5 50 33.97
746 10 50 34.6007
746 10 50 34.6007
767 10 50 30.858
745 10 50 34.8789
746 10 50 34.6007
747 10 50 34.6007
758 10 50 34.6007
772 10 50 34.60
I already grouped the data by entering a new line between blocks. I would like to calculate for each block the mean and standard deviation of the 4th column.
Then I would like to plot on the Y axes the mean with the confidence interval (standard deviation) and on the X axes the value from the second column.
Each data block has a unique number in the 2nd column.
Solution: so far I got the values for a point from the first block but while I try to plot I get an error:
#myBash code for plotting.sh
FILEIN=simulationR.txt
rm plotTestR.png
gnuplot << EOF
reset
set terminal png
set output 'plotTestR.png'
set ylabel 'reward'
set xlabel 'Nr of simualtion'
set title 'Simualtio duration'
set grid
stats "$FILEIN" using 4 every :::0::0 nooutput
mean1 = sprintf('%.3f', STATS_mean)
std1 = sprintf('%.3f', STATS_stddev)
stats "$FILEIN" using 2 every :::0::0 nooutput
x1 = sprintf('%.3f', STATS_max)
plot '-' w yerrorbars title std1
x1 mean1 std1
exit
EOF
and the error:
gnuplot> plot '-' w yerrorbars title std1
^
line 1: Bad data on line 1 of file -
Usually, gnuplot isn't made for such data processing tasks. That's best done with an external script, which does the processing and writes to stdout, which can then be feed directly to gnuplot like
plot '< python myscript.py simulationR.txt'
In your example, you can only have fixed data after the plot '-' part, no variable substitution is done here.
However, gnuplot version 5 introduces a new inline data structure, to which you can write your computed values (set print $data).
Note, that the following is a plain gnuplot script, if you want to wrap it in a bash script (which is not necessary, since you can pass variables to a gnuplot script via the command line), then you must escape the $ characters.
FILEIN="simulationR.txt"
system('rm -f plotTestR.png')
reset
set terminal pngcairo
set output 'plotTestR.png'
set ylabel 'reward'
set xlabel 'Nr of simulation'
set title 'Simulation duration'
set grid
set print $data
do for [i=0:2] {
stats FILEIN using 2:4 every :::i::i nooutput
print sprintf("%e %e %e", STATS_max_x, STATS_mean_y, STATS_stddev_y)
}
set autoscale xfix
set offsets 1,1,0,0
plot $data using 1:2:3 w yerrorbars
A further improvement could be to separate two blocks by two blank lines, in which case you can use
stats 'simulationR.txt' using 0 nooutput
to have the number of blocks in the variable STATS_blocks, and you can rewrite the loop as
do for [i=0:STATS_blocks-1] {
stats FILEIN using 2:4 index i nooutput
print sprintf("%e %e %e", STATS_max_x, STATS_mean_y, STATS_stddev_y)
}

How set point type from data in gnuplot?

How set point type from data in gnuplot?
gnuplot script:
set terminal pngcairo size 640,480
set output "points.png"
set style data points
set auto x
set autoscale x
unset colorbox
plot 'test.data' using 2:1 with points notitle
test.data
32 35 8
34 34 6
36 28 1
34 32 2
28 30 7
38 30 9
34 29 2
35 36 9
39 34 3
31 33 9
28 31 6
35 30 5
33 41 4
32 37 3
how get point type from 3 column?
plot 'gnuplot.data' using 2:1 with points pt (:3) notitle // error
abstraction example:
need:
gnuplot Version 4.6 patchlevel 4
There is no option to select the point type from the data file based on a column (equivalent to linecolor variable, pointsize variable or arrowstyle variable). Basically you have two options:
Iterate over all possible point types (which you can extract with stats if this should be variable) and for each number plot only those points which match the current point type:
stats 'test.data' using 3 nooutput
unset key
set style data points
plot for [i=STATS_min:STATS_max] 'test.data' using 2:($3 == i ? $1 : 1/0) lt 1 pt i ps 2
Use the labels plotting style and a sequence of unicode point symbols from which you select using the value from the third column as index. (use e.g. http://www.shapecatcher.com or http://decodeunicode.org/en/geometric_shapes to find suitable symbols)
unset key
set encoding utf8
symbol(z) = "•✷+△♠□♣♥♦"[int(z):int(z)]
plot 'test.data' using 2:1:(symbol($3)) with labels textcolor lt 1

How to remove palette colors heatmap

Is possible if heatmap palette(small rectangle on the right) to be removed?
this is my data
a b c
1 181 80 121 10 34 20
2 18 20 17 20 13 20
3 12 20 5 30 20 20
this is my gnuplot script
set term pos eps font 20
unset key
set nocbtics
set palette rgbformulae -7, 2, -7
set title "Faults"
set size 1, 0.5
set output 'heatmap2.eps'
YTICS="`awk 'BEGIN{getline}{printf "%s ",$1}' 'data2.dat'`"
XTICS="`head -1 'data2.dat'`"
set for [i=1:words(XTICS)] xtics ( word(XTICS,i) i-1 )
set for [i=1:words(YTICS)] ytics ( word(YTICS,i) i-1 )
set for [i=1:words(XTICS)] xtics ( word(XTICS,i) 2*i-1 )
plot "<awk '{$1=\"\"}1' 'data2.dat' | sed '1 d'" matrix every 2::1 w image, \
'' matrix using ($1+1):2:(sprintf('%d', $3)) every 2 with labels
I want to remove the palette because I adjust the ploting colors by percentage of my data. So, I guess the palette on the right my table is now use anymore. Thanks
That is the colorbox. Just use
unset colorbox
to remove it.

Resources