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

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.

Related

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

gnuplot: how to change fontsize of hypertext?

So far, I couldn't find any documentation about how to change the fontsize of hypertext.
From help hypertext which doesn't say anything about fontsize.
plot 'data' using 1:2:0 with labels hypertext point pt 7 \
title 'mouse over point to see its order in data set'
And the following use of font ",30" does not have any effect:
plot 'data' using 1:2:0 with labels font ",30" hypertext point pt 7
Besides this, help labels lists the possibilty of the following syntax
sprintf("{/=30 %d}",$1**2)
But this and all the following tests don't lead to the desired result: labels and tics in standard size, but only hypertext in larger size.
The last test results in large hypertext and small labels/tics but ugly proportions of the graph. Is there any solution to this?
Code:
### hypertext font size
# Test1:
reset session
set title "default terminal " # in my case wxt
plot '+' u 1:($1**2):($1**2) w labels font ",30" hypertext point pt 7 ps 3 lc rgb "red" notitle
pause -1
# Test2:
reset session
set term wxt font ",10"
set title "explicitely set wxt terminal" font ",10"
plot '+' u 1:($1**2):($1**2) w labels font ",30" hypertext point pt 7 ps 3 lc rgb "red" notitle
pause -1
# Test3:
reset session
set title "only labels without hypertext using {/=30 } syntax"
plot '+' u 1:($1**2):(sprintf("{/=30 %d}",$1**2)) w labels hypertext point pt 7 ps 3 lc rgb "red" notitle
pause -1
# Test4:
reset session
set term wxt font ",30"
set title "setting terminal font to 30"
plot '+' u 1:($1**2):($1**2) w labels hypertext point pt 7 ps 3 lc rgb "red" notitle
pause -1
# Test5:
reset session
set term wxt font ",30"
set title "setting terminal font to 30 and the labels to 10 again" font ",10"
set xlabel font ",10"
set ylabel font ",10"
set xtics font ",10"
set ytics font ",10"
plot '+' u 1:($1**2):($1**2) w labels hypertext point pt 7 ps 3 lc rgb "red" notitle
### end of code
This is a screenshot of the display on the qt terminal from the distributed demo "hypertext.dem" after modifying the plot command as shown to specify a hypertext font that is separate from the default font:
gnuplot> load 'hypertext.dem'
gnuplot> ^C
gnuplot> plot 'cities.dat' using 5:4:(City(1,3)):(Scale(3)) with labels hypertext \
point pt 7 ps var lc rgb "#ffee99" font "VladimirScript,20", \
'cities.dat' using 5:4:(strcol(1)) with labels font ",5"
The same command works for the wxt terminal.
The command more or less works for the svg terminal also but I never figured out how to make the bounding box of the svg hypertext adjust to fit an altered font size.

How to italic text in Times new roman font in gnuplot

I am trying to produce a plot with font of Times new roman in Jpeg terminal.
Gnuplot 4.6 is installed in Windows. I have tried with JPEG terminal and ended with following result by code:
# this script for compare remaining ice area
reset
set term png large font "times new roman" 20 size 700,500 enhanced #500,400
set output 'Compare.png'
#
set xlabel "{/=15 {/Italic Time} (min)}"
set ylabel "{/=15 {/Italic Remaining ice area} (percent)}"
set xrange [0:75]
set yrange [0.5:1.01]
set key top right
plot 'ice_example.dat' u 1:2 w p pt 8 lc rgb 'red' lw 3 title 'Free surface LBM' ,\
'ice_mass.dat' u 1:2 w p pt 5 lc rgb 'black' lw 5 title 'Experiment'
unset multiplot
set term win
unset output
When I change term png to term jpeg, output file is not produced. Also It does not work with {/Times New Roman-Italic Time} (min) for label.
Thanks for advance.

Displaying long labels in Gnuplot

I am currently working for a company where I have to evaluate a survey. Now do I have to make a plot of the data.
They want a table with the questions in the left column and a point in the right column with a distance to the question which symbolizes the average grade[0:4]. My first attempt is using gnuplot because I have used it before and now ran into the problem that if the length of the question(I already shortened them to a max. of 50 characters) is too long gnuplot is having problem displaying the plot correctly. The whole plot gets pushed to the right and you can't read it anymore.
My dataset looks like this
Eltern können sich über unsere Schule vielfä..., 2.2
Eltern werden über wichtige Entscheidungen inf..., 2.4
Eltern wissen über Projekte der Schule Bescheid, 2.4
Eltern erfahren Planung und Durchführung von F..., 1.5
Die Schule hat einen guten Ruf, 2.8
And here is my gnuplot file
set terminal pdfcairo enhanced font "Droid Sans,9" linewidth 4 rounded fontscale 1.0
set output "template.pdf"
set style line 80 lt rgb "#808080"
set border 3 back linestyle 80 #remove top and right border
set xtics nomirror
set ytics nomirror
set datafile sep ','
set xtics 0,1,4.
set ytics font ",4"
set xlabel "Note"
set style line 1 lc rgb "#0060AD" lt 1 lw 2 pt 7 pi -1 ps 1.0
set pointintervalbox 3
set xrange [0:4]
plot 'datafiles/adler_organisation.dat' using 2:0:ytic(1) notitle w lp ls 1
The result I currently get is
Here is an image how the rest of the evaluation looks like(made in LaTeX with datatool, loongtable and LTXtable).
Basically it is enough to fix the left margin with the command set lmargin at screen 0.5. Gnuplot isn't very good at estimating the margins based on the font type and font size. The result I get with this little change is:
Gnuplot cannot wrap long line automatically. You could use the epslatex terminal an put the labels in a \parbox with fixed length to achieve this, like with
label(s) = sprintf('\parbox{4cm}{\raggedleft %s}', s)
set ytics right
plot 'datafiles/adler_organisation.dat' using 2:0:ytic(label(strcol(1))) notitle w lp ls 1
But that would possibly give you problems getting the fonts. I haven't tried using epslatex together with Droid Sans.
As an other option you can use a python script to preprocess your datafile and insert line breaks. With the python script wraplabels.py:
from __future__ import print_function
import sys
import textwrap
with open(sys.argv[1], 'r') as f:
for line in f:
l, v = line.split(',')
print('"{}",{}'.format('\\n'.join(textwrap.wrap(l.strip(), 30)), v), end='')
and the gnuplot script
set terminal pdfcairo enhanced font "Droid Sans,9" linewidth 4 rounded fontscale 1.0
set output "template.pdf"
set style line 80 lt rgb "#808080"
set border 3 back linestyle 80 #remove top and right border
set tics nomirror
set datafile sep ','
set xtics 0,1,4.
set ytics font ",4" right
set xlabel "Note"
set style line 1 lc rgb "#0060AD" lt 1 lw 2 pt 7 pi -1 ps 1.0
set pointintervalbox 3
set xrange [0:4]
set lmargin at screen 0.3
plot '< python wraplabels.py datafiles/adler_organisation.dat' using 2:0:ytic(1) notitle w lp ls 1
you get a nice result

import font in Gnuplot: strange result

I am using the fontfile option to import a font in gnuplot. The font I selected is similar to a computer modern font, but I obtain a very different font.
Here is my code
reset
set term postscript enhanced eps fontfile "/usr/share/texmf/fonts/type1/public/lm/lmr8.pfb" "lmr8"
set output "comparison_inside_fields.eps"
set key spacing 1.5
normTemp=2*pi*750*1E+12
set xlabel "{/lmr8=20 t} ({/lmr8=18 s})"
set ylabel "Re({/lmr8=18 E}_{/lmr8=12 1}) ({/lmr8=18 V/m})" font "lmr8,17"
set logscale y
set yrange [50:1000]
set size 0.65
set tics front
set autoscale xfixmax
plot "Analytic_EField_linear_PW1000.dat" u ($1/normTemp):($2) w l lw 3.0 lc rgb "red" title "E_{1} equa-diff", "EField_linear_PW1000.txt" u ($1):($2) w l lw 3.0 lc rgb "blue" title "E_{1} CST", "exponential_linear.dat" u ($1/normTemp):($2) w l lt 2 lw 1.0 lc rgb "black" notitle`
and here is the image:
The font name is LMRoman8, and not lmr8. Use e.g. kfontview or head -1 .../lmr8.pfb to see the font name.
So a rather minimal example taken from your script would be:
reset
set term postscript enhanced eps fontfile "/usr/share/texmf/fonts/type1/public/lm/lmr8.pfb" "LMRoman8"
set output "comparison_inside_fields.eps"
set xlabel "{/LMRoman8=20 t} ({/LMRoman8=18 s})"
set ylabel "Re({/LMRoman8=18 E}_{/LMRoman8=12 1}) ({/LMRoman8=18 V/m})" font "LMRoman8,17"
plot x title "E_{1} equa-diff"
Result with 4.6.5 is:
The result is ok, but I would recommend you to use the epslatex terminal, which provides much nicer typesetting. Here an examplary document similar to yours:
basename = 'epslatex-test'
set terminal epslatex standalone header '\usepackage{lmodern}'
set output basename.'.tex'
set xlabel '$t$ (s)'
set ylabel 'Re$(E_1)$ (V/m)' offset 1
plot x
set output
system(sprintf('latex %s.tex && dvips %s.dvi && ps2pdf %s.ps && pdfcrop --margins 1 %s.pdf %s.pdf',\
basename, basename, basename, basename, basename))
Instead of using the header option you can also write all the packages and settings you want for all image into a file gnuplot.cfg, which will be included automatically, if available.

Resources