How do I access various true type fonts through gnuplot with png terminal? - gnuplot

I am trying to output a png image with an arial size 14 font. I use mac OS X 10.6 and did not build GNUPLOT myself. I got the program from a website called High Performance Computing for OS X in the package for Octave. Here is what I entered in gnuplot:
G N U P L O T
Version 4.2 patchlevel 5
last modified Mar 2009
System: Darwin 10.0.0
Copyright (C) 1986 - 1993, 1998, 2004, 2007 - 2009
Thomas Williams, Colin Kelley and many others
Type `help` to access the on-line reference manual.
The gnuplot FAQ is available from http://www.gnuplot.info/faq/
Send bug reports and suggestions to <http://sourceforge.net/projects/gnuplot>
Terminal type set to 'x11'
gnuplot> set term png font "arial" 14
Terminal type set to 'png'
No TTF font support, using internal non-scalable font
^
invalid color spec, must be xRRGGBB
gnuplot>
Any help would be greatly appreciated. Thanks!

The following works on Mac OS X 10.5 with gnuplot installed via MacPorts:
set terminal png font "/Library/Fonts/Arial.ttf" 14
The documentation is available via help terminal png (emphasis mine):
If gnuplot was built with support for TrueType (.ttf) or Adobe Type 1
(.pfa) fonts, they may be selected using the 'font {}'
option. is either the full pathname to the font file, or a font
face name that is assumed to be the first part of a filename in one of the
directories listed in the GDFONTPATH environmental variable. That is,
'set term png font "Face"' will look for a font file named either
/Face.ttf or /Face.pfa. Both TrueType and
Adobe Type 1 fonts are fully scalable and may be rotated through any angle.
If no font is specified, gnuplot checks the environmental variable
GNUPLOT_DEFAULT_GDFONT to see if there is a preferred default font.
Update: I just noticed that your gnuplot installation complains about "No TTF font support", so the above may not work for you. In order to get true type fonts to work at all, you probably have to re-install gnuplot.

Thanks! The info with $GDFONTPATH was really helpful for on MacOS.
Adding the line:
export GDFONTPATH=/System/Library/Fonts:$GDFONTPATH
to my /Users/username/.profile solved the Problem for me. Don't forget to source the .profilefile. Or to restart the Terminal. So that the variable gets loaded.

It depends on the terminal type
On (X)Ubuntu LTS GNU/Linux, gnuplot seems to look up fonts in a whole host of directories by default. For example, the following line worked by default with the terminal png:
set terminal png font "texgyrepagella-regular.otf" 12
Even though I had no environment variables set and the package manager had previously installed this font in /usr/share/texmf/fonts/opentype/public/tex-gyre. Nice!
However, if I employ the more advanced terminal pngcairo, the very same font is specified by its name; not its filename. Even nicer!
set terminal pngcairo font "TeX Gyre Pagella, 12"
Please, also notice the syntactic difference in specifying the font size.

Related

Gnuplot: linetype Version 5.0 patchlevel 3

I am using gnuplot 5.9 patchlevel 3 and I wanted to use different lt thus I wanted to reproduce the following this tutorial from gnuplot 5.0 patchlevel 1.
In particular if I copy it and launch it both from term and as .eps I couldn't see dashed lines, here the output
In particular I do not understand the following line:
You will only see dashed lines if your current terminal setting permits it
What does it mean? How I can 'force' gnuplot to print the different dashed lines in .eps, .png or via screen?
I found this guide but its refer to a 4.2.5 version of gnuplot, even if I use:
set termoption dashed
or
set terminal x11 dashed
I can't see the dashed lines...Those are the terminals I can use in gnuplot 5.0 patchlevel 3 from help term:
canvas cgm context corel
dumb dxf eepic emf
emtex epslatex fig hpgl
latex mf mp pcl5
pop postscript pslatex pstex
pstricks push qms svg
tek40xx tek410x texdraw tgif
tkcanvas tpic vttek x11
xlib xterm
I red also this answer but gnuplot 5.0 doesn't support pngcairo (???) as a test, in fact, I just try:
set term pngcairo dashed
And I receive the answer:
Terminal type set to 'unknown'
^
unknown or ambiguous terminal type; type just 'set terminal' for a list
Thus I tried to install pngciaro following this page using homebrew which I found not so useful unfortunately due to the fact that the question about gnuplot 5.0 does not have an answer and because I receive some warning that could be connected with the installation of the pngcairo.
I am using gnuplot 5.9 patchlevel 3
Surely you mean 5.0.3? The image you attached shows dashed lines so what's your question? Then I tried this example script you link to with the eps terminal and it works fine as well on 5.0.3.
Gnuplot renders output using different "terminals", some of the more terminals do not support support dashed lines and this includes the default PNG terminal png, the png terminal from the cairo library, pngcairo, does however support dashed lines. Terminals must be integrated into your Gnuplot build at compile-time, so options must be flagged to enable certain terminals. If Gnuplot was not built with the cairo library then the pngcairo or epscairo terminals will not be available and you will receive that message
unknown or ambiguous terminal type; type just 'set terminal' for a list
when attempting to set you plot to one of those terminals. When you do set term it just displays the terminals which your build was compiled with.
Gnuplot 5 does support pngcairo, it just has to be built with it. Are you on OSX and have homebrew installed? Just install it with cairo support using
brew install gnuplot --with-cairo

gnuplot gif not scalable with ttf font

After installing libgd on RedHat Linux, I found the path to .ttf fonts and used the full pathname to a DejaVu .ttf font (in 'set terminal gif font...") to create a .gif file from gnuplot. It looks good in a Firefox window, but when I change the size, it looks bad, as though the font is not scalable.
I am using the default binaries. Do I need to recompile gnuplot with different settings to make it scalable? I get no errors or msgs when the image is created from gnuplot (i.e. it finds and uses the .ttf file; I know because I tried several fonts and the image responded accordingly, with .pfa fonts also).
The gnuplot documentation says that TrueType fonts are fully scalable. Maybe I don't understand what scalable means. I had a similar problem with SUN OS, and my solution was to create a postscript (.eps) file from gnuplot and then convert it to .gif, and then it was scalable, but I don't have such a conversion utility on Linux (yet), and it seems like an unnecessary step.
I don't have the actual code/output in front of me, but I can add some if it would help. Also, I can't find any arial.ttf fonts on the system. Maybe that is a clue to the problem.
I heard good things about pngcairo (to avoid using gd), but 'set terminal' does not list it as an image type.
This is not a definitive answer, but it allows to show me a picture of the situation on my machine.
This plot was generated as gif using gnuplot 4.6p5 and Suse Linux 13.2.
The upper plot shows labels written in DejaVu, left using the full path to the TTF file, right using the name of the font. (DejaVu is an installed font here.)
The lower plot shows the same, the font is from the game Minecraft (i.e. very pixelated). I do not get any error message about missing fonts or similar, but gnuplot uses its default font here, but not what I want. More interesting: When I do not specify the font, I get Liberation Serif...
However, it seems my system ONLY uses fonts, regardless if referenced by name or path, when the font is correctly installed. Nevertheless, also the default font is smooth and scalable. (the gnuplot help says, gd has some not scalable build-in fonts, which may be used in your plot)

GNUplot add OSX system font to PDF output

I need to use a symbol font called Moon Fonts TTF in the PDF output from GNUplot. GNUplot finds it with no problem in the Aqua terminal.
I've tried:
set fontpath "/Users/house/Library/Fonts/MoonPhases.ttf"
and other add fontfile suggestions from the gnuplot help pages with no luck.
I have also tried a series of .ttf, .otf, postscript and unicode-mapped fonts with some support from a typography expert, with no luck at all: pdfcairo, postscript or epscairo cannot seem to find it.
GNUplot's 'show fontpath' gives:
system fontpath is "/System/Library/Fonts" "/Library/Fonts" "/Users/house/Library/Fonts"
and the fonts are there in one of those paths. I also tried placing them directly in GN's working directory.
If anyone has suggestions about how to make this work it would be much appreciated.
OSX Snow Leopard
GNUplot 4.6.2
You could first use the postscript eps terminal to plot, and then convert the eps to postscript using epstopdf which, at least on my system, embeds the needed fonts into the resulting pdf. If it doesn't you can try to force it by providing the ghostscript parameter directly.
To make your font visible for the postscript terminal, install it into your fontpath and then use
fc-cache -fv
to reload your font cache. The name of the font might vary, because for postscript you have to find the postscript name of the font:
fc-query /path/to/your/font/MoonPhases.ttf | grep postscript
For more examples of this, read this Blogpost:
Schriftarten über Umwege: Gnuplot unter Linux und Mac OS X
It is in german language, but google Translate should help.

Suppress the missing font warning with gnuplot

I am using gnuplot and get this warning everytime I generate a graph:
Could not find/open font when opening font "arial", using internal non-scalable font
Is there a way to suppress the warning?
This warning is generated by the gd backend I believe. Suppressing it might be a little tricky (you could try redirecting stderr of the gnuplot process), but gnuplot seems to like to write useful things to stderr, so I don't advise that ... and the builtin (non-scalable) font looks like garbage. The easiest fix is to see if your gnuplot was built with pango-cairo support. Just try:
set term pngcairo
instead of:
set term png
In this case, the font subsystem of cairo will take over rather than of gd. As a side bonus, I've found that I'm much happier with the cairo plots.
If that's not an option, you can download/find a suitable font and put it in a directory somewhere. Then you can set an environment variable GDFONTPATH to point to that directory. For example, find a truetype font that looks like Arial and put it in ~/fonts/arial.ttf. Then set your environment export GDFONTPATH=${HOME}/fonts and all should work.
If you're willing to live with the ugly font that gd provides, you can use the builtin fonts explicitly:
set term png tiny
or:
set term png large
See help fonts gd for more information.

Plus/minus symbol in gnuplot?

I'm generating .eps figures in gnuplot for inclusion into papers typeset with LaTeX, using
set terminal postscript eps enhanced "Helvetica" 14
This generally works perfectly, but i'm now trying to put together a figure using a label that includes a ± symbol. If I use it directly, e.g.
set label "-56±2"
then it appears correctly on the default 'wxt' terminal but is prefixed by an A with a circumflex (i.e. -56±2) in the postscript output. Using
set label "-56^+/-2"
works but looks rubbish. In the past i've used the 'Angstrom' character (Å) by doing
set encoding iso_8859_1
set xlabel "wavelength (\305)"
but I haven't managed to get this to work either for the unicode representation of ± which I think is \261 (see http://www.fileformat.info/info/unicode/char/00b1/index.htm), i.e.
set label "-56 \261 2"
but I just get an empty space between the -56 and 2. Any ideas on how to do this? Ubuntu 10.10 and Gnuplot 4.4 patchlevel 0, if it's important.
Just for the record, from the Gnuplot perspective the correct answer does appear to be this:
set encoding iso_8859_1
set label "-56 \261 2"
which gives a label
-56 ± 2
It works perfectly on a different machine (same Gnuplot level) so i'm not sure why there's an issue on the original Ubuntu machine; both machines display the resultant .eps file correctly.
To get a more beautiful label, I suggest epslatex terminal. It produces graph part in eps format and text part in latex format. Then you can edit your tex file and inset any special characters latex support.

Resources