Inkscape crops eps files generated with gnuplot - gnuplot

I have a script file to generate an eps file with gnuplot. The basics of this script are:
set terminal postcript enhanced color size 30,20 font 'Times-ew-Roman,40'
set xtics -.5,0.125
set ytics 0.1,0.1
set xrange [-0.5,.5]
set yrange [0.,1.6]
set cbrange [-0.5,.5]
set output "file.eps"
plot #whatever i plot
This script generates an eps file, which I can open in ubuntu and I can see is well printed. Now, I want to import this eps into inkscape, but when importing inkscape imports a big frame with only the top left drawn. The rest is blank. Do I have to change anyvalue in my gnuplot script or do something else with inkscape? I tried to open it in inskcape windows and ubuntu versions, and in both cases it happens the same with the same file.

The problem may be that you have not actually asked gnuplot to produce an eps image. Instead you produced a generic PostScript document with a page size that does not match the default. You need to put the keyword "eps" in your terminal command:
set term postscript eps color size 30,20 font "Times-New-Roman,40"

Related

math latex font in postscript terminal

I know the epslatex terminal can be used to have fonts in latex style.
But how can I emulate math latex fonts in the postscript terminal?
set term postscript size 5,4
set out "test.ps"
pl [][-1.1:1.1] sin(x) t "sin {/Italics x}"
set out
In math latex
it would look like:
So it seems I want a serif font.
IMHO this is far more trouble than it is worth. But if you really want to you can download Adobe Type 1 versions of the standard TeX fonts for use in PostScript, specifically for use by the gnuplot postscript terminal. Here is a demo.
#
# Demonstrate use of TeX Computer Modern fonts in gnuplot PostScript terminal
# This demo requires Adobe Type 1 fonts that may not be installed on your system.
# If necessary you can download them from
# http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/pfb/cmr10.pfb
# http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/pfb/cmmi10.pfb
# http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/patched-pfb/cmsy10.pfb
#
set term post eps color fontfile 'cmr10.pfb' fontfile 'cmmi10.pfb' fontfile 'cmsy10.pfb'
set output 'cmfonts.eps'
set title "Use of TeX Computer Modern fonts in gnuplot PostScript terminal"
set label 1 'Times-Roman: {/Times-Roman abcdefghABCDEFGH}'
set label 2 'cmr10: {/cmr10 abcdefghABCDEFGH}'
set label 3 'cmmi10: {/cmmi10 abcdefghABCDEFGH} {/cmmi10 \013\014\015\016\042}'
set label 4 'cmsy10: {/cmmi10 abcdefghABCDEFGH} {/cmsy10 \013\014\015\016\042}'
set label 1 at graph 0.05,0.6 left
set label 2 at graph 0.05,0.5 left
set label 3 at graph 0.05,0.4 left
set label 4 at graph 0.05,0.3 left
set xlabel "{/cmmi10 \013}"
plot [0:2*pi] sin(x) title "{/cmr10 sin({/cmmi10 \013})}"
Serif (Times) in combination with Oblique (Italic) also emulates a bit the look of latex math.
set term postscript size 5,4
set out "test.ps"
set label 1 'Serif: {/Serif abcdefghABCDEFGH}' at graph 0.05,0.5 left
set label 2 'Serif Oblique: {/SerifOblique abcdefghABCDEFGH}' at graph 0.05,0.4 left
set label 3 'Symbol: {/Symbol abcdefgh}' at graph 0.05,0.3 left
set label 4 'Symbol-Oblique: {/Symbol-Oblique abcdefgh}' at graph 0.05,0.2 left
pl [0:2*pi] sin(x) t "{/Serif sin} {/SerifItalics x}"
set out
This does not fully look as I asked for, but may look even better in documents using Times anyway.
The credit for Oblique goes to http://www.gnuplotting.org/postscript-terminal-with-italic-symbols/.

Not the same font in gnuplot when using command line or gnuplot commands

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.

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')

How to add a pdf image to a gnuplot plot?

I have an image in PDF format and I want to add to an existing gnuplot plot.
My current code is like:
set terminal postscript eps enhanced color solid font "Nimbus Roman No9 L" 35
set output '|epstopdf --filter > Patterns.pdf'
set size 1.8,1.8
set style data histogram
set style histogram cluster gap 1
plot 'Patterns.dat' using ($2/2.90):xtic(1) title col fs pattern 3
and the pdf file is stored in image.pdf.
It can be done, at least with the epslatex terminal. First, for my example, I am going to generate a pdf file which is a gnuplot-generated figure:
set term epslatex standalone
set output "plot1.tex"
plot sin(x)
Now, outside gnuplot, I generate the pdf file (named plot1.pdf):
pdflatex plot1.tex
which looks like this:
To embed this into a gnuplot graph, I use again the epslatex terminal and embed plot1.pdf as I would do with any pdf file in a latex document, using the \includegraphics[]{} environment, with a gnuplot label:
set term epslatex standalone
set output "plot2.tex"
set label at graph 0.75,0.25 '\includegraphics[width=2cm]{plot1.pdf}'
plot x
And, again run pdflatex:
pdflatex plot2.tex
that generates plot2.pdf, which looks like this:
By changing the location of the label you can change the location of the embedded pdf; by changing the width you can change, guess what, the width of the embedded pdf.

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.

Resources