GNUPLOT: Capital gamma in times new roman - gnuplot

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.

Related

How to obtain tilde or approx symbol in gnuplot legend?

I want to use either tilde (~) or approximate symbol (in latex \approx) in the legend of my gnuplot.
I am using epscairo terminal.
I tried seting either:
set encoding iso_8859_1
or
set encoding utf8
and using different commands, for example \176 as descbribed here (http://ayapin-film.sakura.ne.jp/Gnuplot/Docs/ps_guide.pdf), but nothing seems to work.
Thanks in advance! :)
It seems '\~' or "\\~" works for me for tilde. "{/Symbol \273}" produces ≈.

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 do I include greek letter in 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.

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.

Display underscore rather than subscript in gnuplot titles

Short question:
How do I display the _ (underscore) character in a title in gnuplot that is assigned from a variable name in gnuplot?
Details:
I have something like the following code:
items = "foo_abc foo_bcd bar_def"
do for [item in items] {
set title item
set output item.eps
plot item."-input.txt" using 1:2 title item with linespoints
}
This works fine with gnuplot except that the title get changed from foo_abc to fooabc. I don't know if I want to use an escape character because I don't want that to be in the file name. I've tried a couple of different options with single vs. double quotes but I haven't found what I need yet.
Instead of foo_abc, write foo\\\_abc.
Most gnuplot commands which generate labels accept a noenhanced keyword which will prevent gnuplot from using enhanced text for just that string. In this case, it should be sufficient to just do:
set title item noenhanced
An alternative is to create a function which will remove the unwanted text from the string when passing it to set output:
remove(x,s)=(i0=strstrt(s,x),i0 ? remove(x,s[:i0-1].s[i0+strlen(x):]):s)
# Makes me wish gnuplot syntax was more pythonic :-p
#TODO: Write a `replace` function :-). These just might go into my ".gnuplot" file...
I use an inline function to find the index of the first occurrence of x in the string s. I then remove that occurrence via string concatenation and slicing and recursively call the function again to remove the next occurence. If the index isn't found (strstrt returns 0) then we just return the string that was put in. Now you can do:
set output remove('\',item)
set title item
The underscore comes from treating titles as "enhanced text". Turn that off using
set key noenhanced
If you are using the enhanced eps terminal, that is the reason you need to escape the underscore in the first place. There was another related question today which explains the issue a bit. When you set the terminal, try:
set terminal postscript noenhanced <whatever else here...>
That works for me (Arch linux, gnuplot 4.7.0). If the enhanced terminal is essential, below is a partial solution I found. The assumption is that the underscore always appears in the same place in the string.
set terminal postscript enhanced
items = 'foo\_abc foo\_bcd bar\_def'
do for [item in items] {
set output item[1:3].item[5:*].'.eps'
set title item
plot sin(x)
}
This way you can escape the underscore and not have the \ appear in the filename. Note the use of single quotes for the 'items' string; see the previously linked question for details.
I had the same problem about the underscore in the title: such as I needed to write 4_3 subframe and I needed the enhanced postscript. The SIMPLEST way turned out to be from the adjacent post: ``If you are using the enhanced eps terminal, that is the reason you need to escape the underscore in the first place. There was another related question today which explains the issue a bit." - How is # produced in gnuplot?
So, I followed their advice and this worked:
plot 'LC.stats' u 3:4 ti "{/=15 1350 stars in C18 4\_3 subframe}" -
Double escape character before the underscore.

Resources