\odot in gnuplot - mistake - latex

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$)"

Related

Combine gnuplot with latex: method and output

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.

Putting in accented character in gnuplot xlabel

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?

Gnuplot multiplot positions all text incorrectly in epslatex terminal

I am trying to use the multiplot feature of gnuplot to make a inset graphic on the main plot. I can generate the plot exactly as I want with term='wxt' except for the axis labels, which require LaTeX formatting for generating the desired symbols. When I submit the same commands to term='epslatex', the plot is fine, but all text (axis and tic mark labels) is positioned incorrectly.
I thought using the set size & origin commands might have confused the epslatex terminal output, so I attempted to use the layout command and make the plots side by side just to see if the text would print correctly. It did not.
I'm using gnuplot 4.6 patch 4, and Linux Mint 17.
My script is below. The commented sections indicate the original script that used set size and origin commands to manually place the second plot as a inset, rather than side by side.
set term epslatex color font ",16"
unset key
set termoption dash
set style line 1 lc rgb 'blue' lw 2 lt 1
set style line 2 lc rgb 'red' lw 2 lt 3
set style line 3 lc rgb 'green' lw 2 lt 5
set style line 4 lc rgb 'magenta' lw 2 lt 7
set style line 5 lc rgb 'black' lw 1 lt 0
set output "gr-thresholds.tex"
#set size 1,1
# set multiplot
set multiplot layout 1,2
# bigger plot
set autoscale
set ytics scale default autofreq
set xrange[0:14]
set yrange[0:1.7]
set xlabel 'r (\AA)'
set ylabel '$g(r)$'
#set size 1,1
#set origin 0,0
plot "foo1.csv" w l ls 2, \
"foo2.csv" w l ls 3 , \
"foo3.csv" w l ls 1, \
"foo4.csv" w l ls 4
#small inset
#set size 0.4, 0.4
#set origin 0.5,0.15
set xrange[1.2:2.2]
set yrange[0:0.8]
set ytics 0, 0.2, 2
set xlabel ""
set ylabel ""
plot "foo1.csv" w l ls 2, \
"foo2.csv" w l ls 3 , \
"foo3.csv" w l ls 1, \
"foo4.csv" w l ls 4
unset multiplot
set output
The figure that was generated:
It might be a problem with the way you generate a pdf. The two commands dvipdfm and dvipdf produce different outcomes.
If I take your code, but plot sin(x) instead, and use the following in the terminal:
$ latex file.tex
$ dvipdfm file.dvi
I also get a mismatch between the axes and the plots.
If I use dvipdf however everything looks fine:
$ dvipdf file.dvi
Ok,
Per Tom Fenech's suggestion, I made a minimum code sample to reproduce the error, and the issue that arose is a machine state problem. To generate my graphs, I had run the script twice, once using term wxt and then again using term epslatex.
The problem is that somewhere the state of the gnuplot environment is changed and is not reset by this script. Specifically, the first time through, the default placement of the text labels is fine. The second time through, the range and labels are still attached to the size and origin from the last plot, which is the inset. I thought this was due to the order of the commands set origin/size relative to x/ylabel and x/y range, but simply running the below code twice without restarting gnuplot will generate two different plots. The first time is exactly what I wanted, the second time will skew the labels as shown above.
So I have a "solution", but it is fragile. I would appreciate if someone could explain what I need to do to make this script run multiple times without restarting each time.
Cheers,
--Jim
set term epslatex color font ",16"
unset key
f(x) = sin(x)
set output "sin.tex"
set multiplot
set size 1,1
set origin 0,0
set xrange[0:14]
set yrange[0:6]
set xlabel 'r (\AA)'
set ylabel '$g(r)$'
plot f(x)
#small inset
set size 0.4, 0.4
set origin 0.5,0.15
set xrange[1:3]
set yrange[0:4]
set ytics 0, 0.2, 2
set xlabel ""
set ylabel ""
plot f(x)
unset multiplot
set output

How to remove unknown slits when using filledcurve in Gnuplot (epslatex)?

I'm now trying to use filledcurve in gnuplot 4.6, patchlevel 1. Following shows the sample script:
set term epslatex
set output "figure.tex"
set xlabel "\\huge{x-axis}"
set ylabel "\\huge{y-axis}"
set format xy "\\LARGE{%.0f}"
set xrange [0.0:10.0]
set yrange [0.0:100.0]
set xtics 2.0
set ytics 20.0
set xtics offset 0, -0.3
f1(x) = x**1
f2(x) = x**2
f3(x) = x**3
set nokey
plot '+' using 1:(f2($1)):(f3($1)) with filledcurve lt 1 lc rgb "gray60",\
'+' using 1:(f1($1)):(f2($1)) with filledcurve lt 1 lc rgb "gray40",\
'+' using 1:(0.0):(f1($1)) with filledcurve lt 1 lc rgb "gray20"
I don't known why, but it seems that there are white annoying slits between bars. It cannot be get rid of even if I increase the number of set samples.
Is there any idea to remove these slits?
Unfortunately, this is a viewer problem related to the drawing of adjacent filled polygons, see also problematic Moire pattern in image produced with gnuplot pm3d and pdf output or the bug report #1259 cairolatex pdf fill patterns.
In your case you can use a workaround:
When you have only two columns in the using statement, the area is drawn as closed polygon and doesn't show these artifacts (filledcurves closed). So you must fill the area between each curve and the x1 axis (with filledcurves x1).
Because of a bug in the clipping of curves which exceed the y-range, you must do the clipping of the f3 curve yourself (i.e. use f3($1) > 100 ? 100 : f3($1)). This bug is fixed in the development version.
So you script is:
set term epslatex standalone
set output "figure.tex"
set xlabel "\\huge x-axis"
set ylabel "\\huge y-axis"
set format xy "\\LARGE %.0f"
set xrange [0.0:10.0]
set yrange [0.0:100.0]
set xtics 2.0
set ytics 20.0
set xtics offset 0, -0.3
f1(x) = x**1
f2(x) = x**2
f3(x) = x**3
set nokey
plot '+' using 1:(f3($1) > 100 ? 100 : f3($1)) with filledcurve x1 lt 1 lc rgb "gray60",\
'+' using 1:(f2($1)) with filledcurve x1 lt 1 lc rgb "gray40",\
'+' using 1:(f1($1)) with filledcurve x1 lt 1 lc rgb "gray20"
set output
system('latex figure.tex && dvips figure.dvi && ps2pdf figure.ps')
with the result (using 4.6.1):
Note also, that LaTeX commands like \huge don't take arguments, but are switches. Test e.g. \huge{A}BC, this will make all letter huge. Usually you must limit the scope of \huge with brackets like {\huge ABC}, but if the whole label is affected, it is enough to use set xlabel "\\huge x-axis". That doesn't change anything in your case, but may give you troubles in other circumstances :)

Gnuplot - EPS terminal producing extra characters

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

Resources