Indenting or inserting horizontal space before points in gnuplot - gnuplot

I have the following gnuplot inputfile plot.gpi
#!/bin/env gnuplot
set term postscript enhanced
set output "h_CH.eps"
set encoding utf8
set ylabel "HFC value in MHz"
set title "HFC for H in CH"
set yrange [-48:-45.8]
plot -47.6926 title "CBS" lw 2, \
"data" using 1:xtic(2) with linespoints pt 4 ps 2 lw 2 title "pcH-n"
and a data file data containing:
-46.0170, pcH-1
-47.3122, pcH-2
-47.7706, pcH-3
-47.6692, pcH-4
The results using gnuplot 5.1 is the following:
I would like to have some spacing before the data is plotted. I have tried adding "dummy points" to the data file like this:
0,
-46.0170, pcH-1
0,
-47.3122, pcH-2
0,
-47.7706, pcH-3
0,
-47.6692, pcH-4
0,
Which results in this
As you can see, the points are not connected.
My question is: does there exist a way to tell gnuplot to "indent" or insert horizontal spacing before the data is plotted?

Related

Gnuplot - How to make multiple plots and save each one to different files with cairolatex

I need to make a 2d plot and a 3d plot, which I want to save as .tex files, respectively labo2-mag/latex/position-x-y-over-time.tex and labo2-mag/latex/position-3d.tex. Is there anything wrong with my script ?
# General settings
set tics font ", 14"
set tmargin at screen 0.7
set key at screen 0.3, 0.8 font ",14" spacing 1.3 samplen 0.8 box opaque
# set key outside font ",14" spacing 1.3 box opaque
# Send the border to the background
set border lw 0.1 back
set xlabel '$t$ [s?]' offset 1.7;
set ylabel '$Position$ [m?]' offset -1;
# Plot once 'in the air'
# set terminal unknown
plot "labo2-mag/data/output.out" using 1:2 with points pointtype 6 lc rgb "red" title '$x(t)$', \
"" using 1:3 with points pointtype 8 lc rgb "green" title '$y(t)$', \
"" using 1:4 with points pointtype 6 lc rgb "blue" title '$z(t)$'
# pause 70
# reread
set terminal cairolatex pdf size 10cm, 10cm
set out 'labo2-mag/latex/position-x-y-over-time.tex'
MAX_Y=GPVAL_Y_MAX
MIN_Y=GPVAL_Y_MIN
MAX_X=GPVAL_X_MAX
MIN_X=GPVAL_X_MIN
set xrange [MIN_X-(MAX_X-MIN_X)*0.1:MAX_X+(MAX_X-MIN_X)*0.01]
set yrange [MIN_Y-(MAX_Y-MIN_Y)*0.05:MAX_Y+(MAX_Y-MIN_Y)*0.05]
replot
# reset terminal
splot "labo2-mag/data/output.out" using 2:3:4 with points pointtype 6 lc rgb "red" title '$pos(t)$'
set terminal cairolatex pdf size 10cm, 10cm
set out 'labo2-mag/latex/position-3d.tex'
replot
Your splot command is issued while the first terminal is still active and writing to the first output file. You need to change the terminal and output before doing a new plot. The minimum would be to issue unset output after each of your replot statements.
You might want or need to also set a new intermediate terminal type together with the unset output. I don't understand the "in the air" comment in the script. Do you mean you don't actually want to plot it? You want to view it interactively before plotting to a file? Otherwise maybe set terminal dumb? If it is relevant, please clarify.

gnuplot: add values above bar graphs

my gnuplot script plot bar graphs in the following 2D format:
using the following sctipt:
set term pngcairo size 800,600
set termoption noenhanced
set title "$file_name" font "Century,22" textcolor "#b8860b"
set tics font "Helvetica,10"
#set xtics noenhanced
set ylabel "Fraction, %"
set xlabel "H-bond donor/aceptor, residue"
set yrange [0:1]
set ytics 0.1
set grid y
set key off
set boxwidth 0.9
set style fill solid 0.5
plot '<cat' using 2:xtic(1) with boxes
In order to add values above the bars, I've tried to modify it to
plot '<cat' using 0:2:xtic(1) with boxes, '' u 0:2:2 w labels offset 0,1
but the values were not added to the bars, with the following warning
"/dev/fd/63" line 17: warning: Skipping data file with no valid points
I can only test for Windows, but I assume cat under Linux is the equivalent for type under Windows.
So, what is your filename? I would say your filename is simply missing. Check help piped-data.
Something like the following should work:
plot '<cat myDataFile.dat' using 0:2:xtic(1) with boxes, '' u 0:2:2 w labels offset 0,1
But then, what is the difference to using directly the filename?
plot 'myDataFile.dat' using 0:2:xtic(1) with boxes, '' u 0:2:2 w labels offset 0,1

error when trying to add gnuplot histogram labels

I am new to gnuplot, and I am trying to plot this data (gnuplot receives this input from stdin):
Regular 5
Block 3
Symbolic 8
Char 3
Socket 7
with this gnuplot code:
set style data histograms
set style fill solid
set terminal png
set output "plot.png"
plot '-' using 2:xtic(1), \
'' using 0:($2 + .1) with labels notitle
I get the error Not enough columns for this style. What am I doing wrong? If I remove the last line with labels, I am able to plot the histogram. How can I modify it to get data labels on top of each histogram bar?
Three columns of information x y text are needed for with labels. You gave coordinates but no actual text. Try
$DATA << EOD
Regular 5
Block 3
Symbolic 8
Char 3
Socket 7
EOD
set style data histograms
set style fill solid
set yrange [0:*]
plot $DATA using 2:xtic(1), \
'' using 0:($2 + .1):2 with labels notitle
Try this:
plot 'input_file' using 2, '' using 0:2:1 with labels offset 0, char 1
Note that I have added the values in a file named input_file and have set set yrange [0:10] to make the plot nicer to watch
This gives:

GnuPlot: stacked histogram causes hovering bars

since two days I am trying to solve this problem. The bars of this stacked histogram are not printed above each other. They are floating freely around.
Secondly, I only want to print any 5th xtic-label. I am using GnuPlot v 4.6 patchlevel 6.hovering bars in stacked bargraph
Here are the first data rows (generated with libreoffice):
05.06,-,-,1
06.06,3,-,0
07.06,12,-,3
08.06,0,5,4
09.06,7,2,0
10.06,86,2,1
11.06,31,4,1
12.06,17,1,0
01.07,1,7,1
Here comes the command set:
gnuplot> set datafile separator ','
gnuplot> set style data histogram
gnuplot> set style histogram rowstacked
gnuplot> set style fill solid border -1
gnuplot> set xlabel "Zeit"
gnuplot> set ylabel "Anzahl"
gnuplot> set yrange [0:250]
gnuplot> plot 'test.csv' using 2:xtic(1) title "Menge A",''
gnuplot> using 3:xtic(1) title "Menge B",''
gnuplot> using 4:xtic(1) title "Menge C"
Gnuplot seems to get confused with - as only column content. Also a set datafile missing '-' doesn't help. You need a datafile with really empty fields, like
05.06,,,1
06.06,3,,0
07.06,12,,3
If you cannot get LibreOffice to save the data file properly you can use e.g. sed to process the file on-the-fly:
plot "< sed 's/-//g' test.csv" using 2:xtic(1), '' ...
(This works properly if you don't have negative values, which I suppose is the case).
To the second part: Instead of xtic(1) you can also put any expression which evaluates to a string inside of xtic, like
xtic(int($0)%5 == 0 ? strcol(1) : '')
This uses the string in the first column as xticlabel if the row number is a multiple of 5, otherwise an empty string:
set datafile separator ','
set style data histogram
set style histogram rowstacked
set style fill solid border -1
set xlabel "Zeit"
set ylabel "Anzahl"
set yrange [0:*]
plot '< sed "s/-//g" test.csv' using 2:xtic(int($0)%5 == 1 ? strcol(1) : '') title "Menge A",\
'' using 3 title "Menge B",\
'' using 4 title "Menge C"
As Christoph has already explained, the problem is caused by the - in your input data.
Therefore, the best and cleanest solution is to make LibreOffice display missing data differently.
However, everything worked fine for me when I mask the using COLUMNNUMBER part by using $COLUMNNUMBER. Hence, I changed the last line of your code to
plot 'test.csv' u ($2):xtic(1) t "Menge A", '' u ($3) t "Menge B", \
'' u ($4) t "Menge C"
As you see, you can shorten using to u and title to t. Moreover, you should use :xtic(1) only for the first data set.
Here is my outoput

Insertion of Greek letters in a graph legend using GNUplot

I am trying to incorporate greek symbols into my graph using following code, but keep getting similar error twice.
warning: enhanced text mode parser - ignoring spurious }
warning: enhanced text mode parser - ignoring spurious }
reset
# svg
#set terminal svg size 410,250 fname "Times New Roman" \
set terminal svg size 410,250, enhanced fname 'Times New Roman' \
fsize "12" rounded dashed
set output "data1.svg"
set tics nomirror
# color definitions
set style line 1 lc rgb "#8b1a0e" pt 1 ps 1 lt 1 lw 2 # --- red
set style line 2 lc rgb "#5e9c36" pt 2 ps 1 lt 2 lw 2 # --- green
set key bottom right
plot "abc.htm" using 1:2 title "N('\alpha', T)" w lp ls 1, \
"abc.htm" using 1:3 title "N(\beta, T)" w lp ls 5
PS: The code was running fine until I enabled enhanced mode of svg terminal, as I needed it for inserting greek letters in my graph legends. I am using version 4.6, patch level 5. Can any one help me out?
The correct way is to
use enhanced option of the terminal (you did)
wite {/Symbol a} for an alpha.
Search for symbols + gnuplot on the web, you'll find lists like http://mathewpeet.org/lists/symbols/ with codes understood by gnuplot!
Use a proper encoding (UTF-8) and insert the characters directly:
reset
set encoding utf8
set terminal svg size 410,250 enhanced fname 'Times New Roman' fsize "12" rounded dashed standalone
set output "data1.svg"
set linetype 1 lc rgb "#8b1a0e" lw 2
set linetype 2 lc rgb "#5e9c36" lw 2
set key bottom right
set style function linespoints
set samples 11
plot x title "N(α, T)", 2*x title "N(β, T)"
choose font 'Symbol'
choose corresponding English alphabet for Greek letter, eg. i have chosen 'c' for 'chi', below is the link for other characters.
http://folk.uio.no/hpl/scripting/doc/gnuplot/Kawano/label-e.html
fontsize can be changed easily.
eg...
set ylabel "c" font "Symbol,14"
will produce greek letter 'Chi'.
I have found the way to solve this problem. The Greek letters can be inserted in SVG file using following path in the Inkscape:
Go to Text drop down menu and then click on Glyphs. Next, select font family such as Times New Roman. After that select Greek from script and all from Range options, respectively. Then Greek letters could easily be inserted in the Graph.

Resources