The gnuplot docs have this to say about fonts:
Five basic fonts are supported directly by the gd library. These are
`tiny` (5x8 pixels), `small` (6x12 pixels), `medium`, (7x13 Bold),
`large` (8x16) or `giant` (9x15 pixels).
But when i try to use one:
gnuplot> set terminal png font tiny
I get:
Could not find/open font when opening font tiny, using default
How do I use these seemingly built-in fonts?
The problem was that, for these fonts for some reason, you don't use the standard syntax I tried above:
gnuplot> set terminal png font tiny
But instead, you drop the word "font" for these five special fonts:
gnuplot> set terminal png tiny
Related
I have a sequence of gnuplot commands that produces a label with an underscript _{1} and the Ω symbol {/Symbol W} preceded by a small space &{.}, which
show correctly in the wxt window
show correctly on a SVG file exported from the wxt window
shows no underscript and .W if plotted to the SVG terminal
Here's a snippet of the code:
set label 3 "R_{1} 100&{.}{/Symbol W}"
set terminal svg size 1024,768 dynamic font 'Lohit' fsize 14 enhanced background 'white'
set output 'svg-file.svg'
plot ...
set terminal wxt 0 font 'Lohit,14' enhanced
set output
plot ...
I set both terminal to enhanced mode. What am I missing?
It's probably better these days to input Unicode directly, rather than using the Symbol font. Ω!
The output of your example with gnuplot's svg terminal contains the label as
<tspan font-family="Symbol" >W</tspan>
which leaves it to the viewer/browser to display it correctly. Your example works fine for me with Chrome/Edge, but not with Firefox.
The output of the wxt-svg-export doesn't contain text like show above, but the text is converted to paths in order to avoid such platform and viewer dependency (but has other drawbacks)
I have a file containing some commands :
$ cat components.plg
set terminal png
set output output
set font "Helvetica,10"
unset xtics
unset ytics
unset border
plot "reportGraph_0" with lines title "Component 0", "reportGraph_1" with lines title "Component 1", "aoi.txt" with lines title "Area of interest"
$
I won't display the contents of reportGraph_# here, but anything with 2 points in them is valid.
I then launch gnuplot with this file as parameter, and I get a warning about Arial (I'm not entirely sure why).
$ gnuplot -e "output='footprint.png' " components.plg
Could not find/open font when opening font "arial", using internal non-scalable font
$
However, the result image has its text in non-Helvetica (but more in something like Monospace sans).
Here are the two images (first the output of the command line, second the output of the same sequence of commands launched in a gnuplot shell, and exporting the result image). There is one difference, I didn't use the first two commands (set terminal png and set output output) in gnuplot - I merely "exported" the image as png.
The question is : why don't I have the same font in these two images?
I would like to have Helvetica (or Lucida Grande, but not a monospace font).
Gnuplot has a large variety of terminals. When you launch an interactive gnuplot session and plot you probably use the wxt or qt terminal. By exporting the image from the plot window you save the image as theyes were created by those terminals.
Now, with set terminal png you use a different and quite old terminal, with different capabilities, especially regarding font rendering.
If you want to save your image directly as png, use the pngcairoterminal, which produces higher quality images (the result should be equivalent to that of the exported image from wxt).
The pngcairo, or the pdfcairo terminals should also handle your fonts properly.
The png terminal is older than pngcairo, but it can still use a specified font. You can just specify a path to a .ttf or .pfa font file:
set terminal png font "/path/to/your/Helvetica.pfa"
or a comma-separated pair of the font file path and point size:
set terminal png font '/usr/share/fonts/liberation/LiberationSans-Regular.ttf,9'
gnuplot uses libgd so if you set the environment variable GDFONTPATH to the directory containing your .ttf or .pfa font files, you can specify just the font name instead of the full path:
set terminal png font 'LiberationSans-Regular'
Documentation for setting fonts with different terminals is available within gnuplot under help fonts gd, help fonts cairo, and help fonts postscript.
UPDATE: this issue has been resolved in newer versions (>5.0) of gnuplot; see #andyras' answer.
I am having difficulty getting gnuplot to create labels with bold and enhanced text in non-postscript terminals. The following script
#!/usr/bin/env gnuplot
reset
set terminal pdfcairo enhanced color lw 3 size 3,2 font 'Arial-Bold'
set output 'output.pdf'
set tics scale 0
plot -x title 'normal text', \
-2*x t 'enhanced_{text}', \
-3*x t '{/Arial-Bold attempt to specify_{font}}'
set terminal pngcairo enhanced color lw 3 size 400,300 font 'Arial-Bold'
set output 'output.png'
replot
set terminal postscript enhanced color lw 3 size 6,4 font 'Arial-Bold'
set output 'output.eps'
replot
reset
Produces the following eps (converted to png with convert output.eps -rotate 90 outputeps.png):
which is fine. However, when I use the pdf or png terminals the result looks like this:
Note that while all the label text should be bold, only the label without any enhanced text is bold. In addition, when I try to manually specify the font (last line title) the font is different (reverts to the default?).
Is this behavior I should expect when not using the postscript terminal? Is there another way to specify fonts (i.e. is the naming scheme different outside of postscript)?
Since version 5.0, gnuplot has a new syntax to handle this issue:
"normal text {/Times:Bold boldface-newfont} {/:Italic slanted-default-font } back to normal text"]
These brackets can also be nested.
For Better results in pdf format.
Plot the curves using enhanced eps terminal. Then use Imagemagic to convert your output to pdf format. using the commands
convert myPlot.eps myPlot.pdf
Default resolution with this commands generates a poor output. This can be overcome by using density option with a value of 300. Modified command looks like
convert -density 300 myPlot.eps myPlot.pdf
I found that this preserves all the text formatting of eps file in pdf file.
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.
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.