How do I include greek letter in gnuplot? - gnuplot

I'm using ubuntu 14.04 and gnuplot-x11, and found that for greek letter alpha,
{/symbol a} will work, but that just shows me {/symbol a}, not greek letter alpha.
I tried {\symbol a} or other options, but that does not work..

Using the syntax {/Symbol a} requires that you enable the enhanced mode. This can be done in several ways:
When setting the terminal
set terminal ... enhanced
After setting the terminal with
set termoption enhanced
Explicitely for a single label
set xlabel '{/Symbol a}' enhanced
Depending on the output terminal you are using, the best option is to use utf-8 encoding and directly input the characters:
set encoding utf8
set xlabel 'α'

After using enhanced mode, take care for using {/Symbol a}, you have used {/symbol a}, small letter of "s" in Symbol, so you were not getting greek letter alpha.

Related

GNUPLOT: Capital gamma in times new roman

I want to write the xtics font in times new roman, but one letter is the Symbol Gamma.
The code before the plot input is
reset
set encoding utf8
set xtics font "times new roman, 15"
set ylabel ("E[eV]")
set yrange[-2:2]
set xtics(" ~^J^{/Symbol=16 ^-}" 0.00000, " ~^{/Symbol G}^{/Symbol=16 ^-}" 0.66460, " ~^K^{/Symbol=16 ^-}" 1.60450, " ~^J^{/Symbol=16 ^-}" 2.26910)
The other stuff is just added because I needed a bar above each letter.
So the question is: what should I use instead of
{/Symbol G}
in order to get the Gamma in times new roman like the other letters.
I don't want to use the latex enhancement because I tried it once and the output was just ugly. So please take into account that I just want to use a *.p file.
Thank you in advance.
Make sure your terminal in in enhanced mode. You have already set the encoding properly. Make sure that your editor actually encodes your file as UTF-8!
If your times new roman actually contains the glyph for Γ (code-point 0x0393), then just insert this symbol into the gnuplot file.

Symbols in gnuplot

I thought I knew how the {/Symbol x} worked in gnuplot but I don't. I need to get a partial derivative symbol (utf8 code U+2202), and I can't. How could I do it. I haven't found anything online. This is the document settings:
set terminal postscript eps enhanced color font "Helvetica, 20"
set encoding utf8
Thank you
If you really need to use a postscript terminal, use
{/Symbol \266}
Your gnuplot distribution should contain the file ps_guide.ps. That explains all the character codes available in postscript.
In general I would second Christoph's suggestion to use a cairo terminal. In combination with UTF-8 input encoding and a proper font you can easily include more characters in your output.
When I generate plots for inclusion in TeX documents, I tend to use the same font as the body text (in the example below "TeX Gyre Pagella")
set terminal pdfcairo enhanced color dashed font "TeX Gyre Pagella, 14" \
rounded size 16 cm, 9.6 cm
set encoding utf8
Use any of the cairo-based terminal (pdfcairo or epscairo) and insert the character directly into your script:
set encoding utf8
set terminal pdfcairo font ',20'
set output 'partial-derivative.pdf'
set xlabel '∂u/∂x'
plot x

How to run a system command in gnuplot

I'd like to make gnuplot scripts to output *.eps files and change them into .pdf type automatically. I have a test demo which goes as:
set term postscript eps enhanced color
set output "SystemCommand.eps"
plot sin(x)
set xl "x"
set yl "y=sin(x)"
system(sprintf("epstopdf %s",SystemCommand.eps))
but it doesn't produce what I want, an error comes out every time that says:
"SystemCommand.gp", line 6: undefined variable: SystemCommand
I have tried to use SystemCommand or SystemCommand.eps, no difference here. Anyone has a suggestion?
I use Ubuntu 14.04 and bash shell.
You need to quote the filename in sprintf.
set term postscript eps enhanced color
set output "SystemCommand.eps"
plot sin(x)
set xl "x"
set yl "y=sin(x)"
system(sprintf("epstopdf %s","SystemCommand.eps"))

Gnuplot symbols in epslatex terminal with dots inside

When creating symbols in combination with the epslatex terminal in Gnuplot 4.6, I always notice that in the center of the symbol a small dot is shown (clearly visible on zoom-in). This annoys me quite a bit, as it does not happen in, for example, the png terminal of Gnuplot.
Is there a simple method in Gnuplot to get rid of this dot?
Minimum reproductive example:
set terminal epslatex
set output "test.tex"
test
It can be directly observed in the outputfile test.eps.
Additional info:
I use the following code to create a complete eps-file out of it
\documentclass{article}
\usepackage{graphics}
\usepackage{nopageno}
\usepackage{txfonts}
\usepackage[usenames]{color}
\begin{document}
\begin{center}
\input{test.tex}
\end{center}
\end{document}
Is there a solution inside gnuplot?
According to this answer: https://stackoverflow.com/a/16358393/1134387 there are much more symbols than the few shown by test in Gnuplot. When using 64, 65 and 66 as pointtype, I get symbols without the dot inside, which effectively solves my problem.
Since an other question (Removing dot from centre of empty gnuplot point) has been marked as "duplicate" with no more possibility to answer, I put my answer here to provide some test code and images.
You can do a point test sequence yourself in any terminal.
### Terminal test dots
reset session
set colorsequence classic
set terminal postscript color
# set terminal pngcairo
# set terminal pdfcairo
# set terminal qt
# set terminal wxt
set output "TestDot.eps" # in case of file output set the extension according to terminal
N = 160
M = 10
set parametric
set xrange [-0.5:M-0.5]
set yrange [-M/2:N]
set xtics 1
set ytics M
plot for [i=0:N-1] i%M,floor(i/M)*M w p pt i ps 3 notitle
unset parametric
set output
### end of code
postscript terminal:
pngcairo terminal:

gnuplot - adjust horizontal spacing of subscript letters

I am trying to adjust the horizontal spacing of letters in subscript in the postscript (enhanced) terminal. The default is to align the spacing as you would for normal letters, but for big letters such as P, the subscripted letter appears too far away. Is there a way to adjust the spacing of subscripted letters?
Edit: minimal example, as requested. My use case is with Times-Italic font, so that's what I've done here, but the look is similar with Times-Roman
set term post enh eps font "Times-Italic"
set output "test.eps"
set title "{P_{/*0.75 C}}"
plot sin(x)
set output
Edit 2: I'm pretty sure the reason is that the typesetter is aligning the left side of the second letter at the right edge of the first letter, but for letters like P where there is a large space between the bottom left corner and furthest right point, it doesn't look very nice when a letter is subscripted next to the P (or T, etc.)
If you are picky about typography, then maybe you should use LaTeX. Gnuplot has a variety of LaTeX terminal types, such as tikz, epslatex, and cairolatex. The downside is that you must then pass the generated plot through latex or pdflatex in order to render it, so plotting is not interactive. Also, you must learn some basic LaTeX.
There is a nice tutorial on using the TikZ terminal. That page gives the following example gnuplot script (xlabel added by me):
set term tikz standalone color solid size 5in,3in
set output 'sin.tex'
set xlabel '$t_{\alpha\beta}$'
set xrange [0:2*pi]
plot sin(x) with lines
exit
Note that the exit is important, otherwise sin.tex will be incomplete. To turn this into a PDF, run pdflatex sin.tex.
You still cannot control the positioning of the subscript (well, probably LaTeX will let you do this if you are expert enough), however the defaults were chosen by typographic experts who probably have a better eye than you or me.

Resources