How to italic text in Times new roman font in gnuplot - 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.

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: 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 make a plot of positions with palette in Gnuplot?

How can I make a plot with some values of delta_x and delta_y positions; where I need to use palette (or colorbars) for each point showing their respective epochs (My current plot, and an example of the plot that I would like to make are shown below).
My current Gnuplot code is as follows:
set fontpath '/System/Library/Fonts'
set term post color enh eps font "Helvetica" 14
#Gnuplot script file for plotting data
#Set Line style
set style line 12 lw 1 ps 1 pt 8 # empty triangle
set style line 13 lw 1 ps 0.7 pt 81 #empty circle
#Add Legend
set key top right box
# set plot
set xrange[1.2:0]
set xlabel "Relative R.A. (mas)" # set xlabel
set mxtics 4
set xtics 0, 0.1, 1.2
set yrange[0:1]
set ylabel "Relative decl. (mas)"
set mytics 4
set ytics 0, 0.1, 1
plot "MOD1.dat" using 1:2 w points ls 13 lc rgb 'black' title "Data1", "MOD2.dat" using 1:2 w points ls 12 lc rgb 'gray' title "Data2"
Where my data are as follows:
Data1:
#Year RA(mas) DEC(mas)
1993-06-26 0.36315 0.23913
1993-12-16 0.33392 0.28443
1994-01-28 0.34606 0.30810
1994-12-23 0.37139 0.32989
1995-02-12 0.34050 0.29165
1995-08-17 0.55405 0.42913
1995-12-18 0.36928 0.2777
1996-04-07 0.49601 0.31533
1996-12-13 0.43557 0.34637
1997-11-14 0.36811 0.25562
1998-06-02 0.55603 0.36268
1998-12-07 0.52873 0.23110
2000-11-12 0.45839 0.22572
ieData2:
#Year RA(mas) DEC(mas)
1993-06-26 0.63633 0.44645
1993-09-18 0.63548 0.35586
1993-12-16 0.63161 0.41704
1994-01-28 0.27266 0.47256
1994-03-14 0.75819 0.65255
1994-04-21 0.69664 0.68481
1994-06-21 0.78735 0.72865
1994-08-29 0.91143 0.78274
1994-10-30 0.55326 0.43258
1994-12-23 0.67065 0.54423
1995-02-12 0.55778 0.51656
1995-08-17 1.01458 0.50502
Thank you.
try the palette linetype, like this:
plot 'MOD1.dat' u 2:3:1 w p pt 7 ps 2 lt palette

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