gnuplot - adjust horizontal spacing of subscript letters - gnuplot

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.

Related

gnuplot: why is linewidth 0 not zero in width?

What is the reason that lw 0 doesn't have zero linewidth, i.e. invisible?
What I find in the gnuplot manual:
The line width and point size are multipliers for the current
terminal's default width ...
Ok, if lw 0 is a multiplier then the resulting linewidth should be zero independent of the terminal's default linewidth.
The reason for asking is to eventually have the possibility to use with linespoints and programmatically switch within a loop between with lines and with points.
Code:
### linewidth 0 isn't zero
reset session
set key out
set yrange[-0.9:10.9]
set ytics 1
plot for [i=0:10] i with lines lw i title sprintf("linewidth %g",i)
### end of code
Result:
By the way, what are the artefacts at the y-axis e.g. at ytics 3,4,6,7,9,10 (wxt-terminal)?
Mike Nakis is correct that for at least some of the gnuplot output terminals, including PostScript, gnuplot asks for a 0 width line and the language or library in question interprets that as "1 pixel" or "thinnest possible line".
Similarly "pointtype 0" is not truly missing, it produces a single pixel dot.
You can, however, disable the line drawing altogether by using linetype "nodraw".
That gives a complementary pair of commands
plot sin(x) with linespoints lt nodraw pt 7 # only the points are visible
plot sin(x) with linespoints lt 1 pt 0 # only the lines are visible
In some circumstances it may help to know that the numeric equivalent for lt nodraw is lt -2.
I don't know for sure what the official explanation is for gnuplot in particular, but in my experience, most graphics packages / tools / libraries etc. use a special convention for a line width of zero.
According to this convention, a line width of zero does not mean invisible; it simply means "the thinnest line possible". This means the thinnest line that can be displayed on the device, regardless of zoom, transformations, logical-to-physical mapping, etc.
So, on monitors, it will be a line which is one pixel wide.
On a printer, it will be the thinnest line that the printer is capable of producing. So, if the printer has a high enough resolution, then the line might practically be invisible, though a magnifying glass should still be able to reveal its existence.
And note that "regardless of zoom, etc." means that even if you set up some scaling that makes your 10-point line look as thick as 100 pixels, the zero-width line will still be exactly one pixel thick.

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.

Can letter spacing be set somehow in gVim Editor

I've discovered many sources which have said it cannot be tightened up and that the space between letters within a word is not something the user can adjust. At first I didn't believe it, but after applying a few tips such as this and having the editor continue to display text with the letters evenly spaced, I wonder.
Has anyone experienced or come across a way to set letter spacing?
Vim (out of necessity, because it runs in the terminal) and GVIM (for consistency) use a cell-based addressing scheme, so they require a fixed-size matrix of screen cells. On Windows GVIM, you even can only use fonts that are fixed-width.
Therefore, the only way to influence the perceived spacing between letters is through the selected font (and its size). If you feel that the letters are too far apart, you need to either edit the font (to reduce the width of all characters), or choose another one.
GVIM does allow to tweak the vertical padding between screen lines through the 'linespace' option, though.

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.

Setting linespace in gVim

When setting linespace to some value greater than zero, the characters in the line are vertically top-aligned. I want the characters to be vertically centered (in the middle of the line).
The 'linespace' setting allows to slightly adapt the visual spacing of lines to the used font (so that text is neither too dense nor too much apart). It is not meant to be used for the "widely-spaced lines" effect shown in your screenshot.
If you really need something like that, you'd need to patch Vim's source code, or use another editor, or what I would attempt is modifying the used font to include more vertical padding in all glyphs.

Resources