Plus/minus symbol in gnuplot? - 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.

Related

Introduce a box with special symbols in Gnuplot

I want to have a gnuplot with a box on the right top corner like the one below. My difficulties are both:
how to get \hat{Q} in a the legend?
how to add a box containing the titles?
set term cairolatex eps standalone size 3in,3in
set output 'Q.tex'
set key box opaque samplen 0.5
plot for [i=1:4] sinc(x)**i title sprintf('\tiny${\hat{Q}=%d}$',i) lw 2
The standalone keyword wraps the output in minimal LaTeX commands so that you can run latex Q directly. Omit this if you want to produce a LaTeX fragment for including in a larger document.
I show how to construct a formatted title that includes a LaTeX font size. Note that the format uses single quotes rather than double quotes.
This example uses cairolatex eps because you specifically asked about an eps file. Normallay I would use cairolatex png or cairolatex pdf and process afterwards with pdflatex rather than plain latex.
If you want to include your figure into LaTeX, you should use the terminal cairolatex, then you can include LaTeX code in your plots:
plot "your.data" title '$\hat{Q}=10$'
Concerning your second question, have a look at the manual concerning set key.

Gnuplot Postscript Special Characters Math Equation

I`d like to write the math stuff into a plot using gnuplot 5:
I am using the terminal postscript enhanced because as far as I know this terminal is the only only capable of doing such things.
I used this code:
set label 1 at 400,200 '{/Symbol=50\362#_{/=15 350}^{/=15\154}}' front
This gets me everything except the subscribed averageunder the lambda symbol.
I tried everything with {,}and so on but I think I missing the part where I can escape the /SymbolStyle.
Many terminals support enhanced text, not only the postscript terminal.
In order to use another font than /Symbol for the subscript you could change the font explicitely to a different one for this. However, a better approach is to change the nesting so that /Symbol affects only two parts:
set label 1 at 0,0 '{/=50{/Symbol \362}#_{/=15 350}^{/=15{/Symbol \154}_{/=10 average}}' front
plot x
Output with gnuplot 5.0 with wxt is
If you're using the postscript terminal anyway, you could give a try to the epslatex terminal (or cairolatex):
set terminal epslatex standalone color colortext
set output 'equation.tex'
set label 1 at -5,5 '$\displaystyle\int_{350}^{\lambda_{\mathrm{average}}}$'
plot x
set output
system('latex equation.tex')
system('dvips equation.dvi')
system('ps2pdf equation.ps')

bold enhanced text in gnuplot

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.

how to rotate 3D image in gnuplot

Do we have a facility to rotate the image, using mouse, to see different views in gnuplot.
I wish gnuplot had similar facility to rotate the image as MATLAB has.
In my version it just works.
Version 4.4 patchlevel 0
last modified March 2010
You might need to change the terminal for gnuplot.
The window with the nice toolbar is generated by the "wxt" terminal.
gnuplot> set term wxt
Use 'set term' without parameters to show a list of available terminals.
gnuplot> set term

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

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.

Resources