I'm running gnuplot Version 5.0 patchlevel 5, on MacOSX.
My gnuplot MWE is:
set terminal postscript eps size 4.5,3.5 enhanced color font 'Times-Roman,25' linewidth 2
set out "plot.eps"
set xlabel "~{/Symbol l}{.8\^}_s"
set ylabel "Ylabel" offset 1.5
plot [-10:10] sin(x)
However I get the error
warning: enhanced text parser - spurious }
warning: enhanced text parser - spurious }
This is the problem with the line
set xlabel "~{/Symbol l}{.8\^}_s"
If I write this, it works fine:
set xlabel "~{/Symbol l}{.8-}_s"
However I want to use this accent ^ on top of the lambda symbol. How to do it?
Related
I generated an image with gnuplot using epslatex as terminal.
set term epslatex "enhanced"
Two files are created, a .tex file and a .eps file.
When I insert the image in my LaTex document, and I build latex->pdf, everything is very nice but the fonts are too big, the following fonts:
1. xlabel, ylabel, zlabel
2. xtics, ytics, ztics
3. title
4. key
are all too big, they are basically the same size (and type) of the LaTex document (10pt).
How could I make them smaller? I am sure it is not changing each of them in the gnuplot file, it needs to be something in the terminal options. I tried (removing "enhanced")
set terminal epslatex font ',8'
but nothing change, same fonts as before. In the Warnings in LaTex I get:
pdflatex> LaTeX Font Warning: Font shape `OT1/enhanced/m/n' undefined
pdflatex> (Font) using `OT1/cmr/m/n' instead on input line 8
and then also:
pdflatex> LaTeX Font Warning: Some font shapes were not available, defaults substituted.
what can I do? Thanks
You can use one of the following ways to control the size of the text in the plot
set xlabel "\\begin{<size>} <your_label> \\end{<size>}"
you can use the common size identifiers of LaTeX \tiny \scriptsize \footnotesize \small \normalsize \large \Large \LARGE \huge \Huge, which gives you control and uniformity of the font size over the whole document.
You can also use set ylabel "\\scalebox{<factor>}{ <your_label> }" where factor is a real number, the thing with this method is that it can be a little hard to predict the final font size without testing it several times and adjusting the value of factor.
And the double backslash is to escape the backslash itself in gnuplot
I would like to remove unnecessary margins (gray part in the figure below) in a PDF figure generated by epslatex (gnuplot).
Following are scripts and commands to create the figure.
set term epslatex standalone
set output "figure.tex"
set xlabel "\\LARGE $x$"
set ylabel "\\LARGE $y$"
set format x "\\Large{%.1f}"
set format y "\\Large{%.1f}"
set key left top Left
set size square
set xrange [0.0:1.0]
set yrange [0.0:1.0]
plot x with lines dt 1 lw 5.0 lc rgb "red" title "\\Large $y = x$",\
x*x with lines dt 2 lw 5.0 lc rgb "green" title "\\Large $y = x^2$",\
x*x*x with lines dt 3 lw 5.0 lc rgb "blue" title "\\Large $y = x^3$"
and commands
$ gnuplot sample.gp
$ pdflatex figure.tex
Instead of pdflatex, xelatex would also work. I would like to directly convert to PDF file.
It will be super good if we can remove these margins without too much effort (such as removing the margin manually one-by-one).
Thanks!
If you check help latex, it will tell you that default size is 5 x 3 inches.
Since you set size square, there will be for sure an "unwanted" left and right margin.
What you can do to at least minimize the margins is to set the terminal size to square size as well, e.g. to 3 x 3 inches.
However, keep in mind the graph size is square but x and y axes have tics and labels which require space depending on numbers and labels which might be different for x and y.
set term epslatex standalone size 3 in, 3 in
From help latex:
Syntax:
set terminal {latex | emtex} {default | {courier|roman} {<fontsize>}}
{size <XX>{unit}, <YY>{unit}} {rotate | norotate}
By default the plot will inherit font settings from the embedding
document. You have the option of forcing either Courier (cmtt) or
Roman (cmr) fonts instead. In this case you may also specify a
fontsize. Unless your driver is capable of building fonts at any size
(e.g. dvips), stick to the standard 10, 11 and 12 point sizes.
...
Maybe, there are LaTeX commands to crop the graph to its bounding box.
Thanks to #AlainMarigot help, I change the system to Lua tikz with the option tightboundingbox.
Looks good, but not exactly same as epslatex.
What is wrong in (R_$\odot$)$ please?
set terminal epslatex standalone color
set output 'plot.tex'
set xlabel "$v$ (R$\odot$)"
set ylabel "$u$ (R$\odot$)"
plot [-1:1] [-0.6:0.6] 'file.txt' with points pt 7 ps 0.7 lc rgb "navy" notitle
It writes odot instead of sing. Thank you
Be careful of the difference between strings in single quotes and strings in double quotes. Because of the double quotes, the backslash at the start of "\odot" is treated as an escape character rather than a literal. Either use single quotes:
set xlabel '$v$ (R$\odot$)'
set ylabel '$u$ (R$\odot$)'
or add an additional escape to preserve the backslash:
set xlabel "$v$ (R$\\odot$)"
set ylabel "$u$ (R$\\odot$)"
I'm running the following script:
#!/bin/bash
gnuplot -e "set t latex ; set size 0.5,1; set output 'grafico.tex';
set xtics ('$\frac{-\pi}{2}$' -pi/2, 0, '$\frac{\pi}{2}$' pi/2); set xrange [-pi/2:pi/2];
set yrange [-2:2]; set ylabel '$ f(x)$'; set xlabel '$\theta$';
plot sin(x); pause -1 'hit return to continue'"
pdflatex latex
atril latex.pdf
Output 1
As a beginner both with programming and gnuplot, I want to be sure that's the correct way to do it. My doubt come from the output, it doesn't looks very good (the resolution, mainly). Is there any simple improvement i'm missing? Any change to improve the plotting technique and enhance the result will be welcome.
Output 2
Changing latex to cairolatex pdf as suggests #Ethan Merritt returns:
which is much better.
gnuplot's original latex terminal, the one you get by saying "set term latex", is horrible by modern standards. Use one of the more recent ones. My favorite is the tikz terminal:
gnuplot>
set term tikz standalone size 5cm, 7cm
set output 'grafico.tex'
set xtics ('$\frac{-\pi}{2}$' -pi/2, 0, '$\frac{\pi}{2}$' pi/2)
set xrange [-pi/2:pi/2]; set yrange [-2:2];
set ylabel '$ f(x)$'; set xlabel '$\theta$';
plot sin(x)
unset output
system("pdflatex grafico")
Notes:
You should probably set the size as part of the set term command. If you use set size your output will contain large blank areas
Your local copy of gnuplot might not support the tikz terminal. In that case you could use set term cairolatex pdf instead, with everything else the same.
gnuplot has other (too many!) latex-based terminals also, but I suggest starting with tikz or cairolatex.
I have gnuplot file that is outputting quite nicely in EPS but I'm suffering some issues when it comes to the labels. For some reason, a random figure (') is being inserted before the each label. This isn't being produced in a PNG export.
Example gnuplot error picture
The gnuplot file is below
set term postscript eps enhanced
set datafile separator ","
set datafile missing "NULL"
set decimal locale
set output 'Average_Costs_Plotted.eps'
set grid
set key left
set ytics nomirror
set xtics nomirror
set format y "£%'.0f"
set ylabel "Total Loss Estimate \n Based on Average Cost Per m^2"
set xlabel "Area Damaged m^2"
plot "Average_Costs_Upto_10000mSQM.csv" using 1:2 axis x1y1 title 'Industrial Processing' w l lw 2
Well that'll teach me to RTFM.
Postscript doesn't support unicode as mentioned above - however there are octal codes for symbols to insert them.
The £ is input by using the code \243