bold enhanced text in gnuplot - 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.

Related

Inkscape crops eps files generated with 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"

Ohm symbol shows in gnuplot wxt window, exported SVG from the window, but not in SVG term output

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)

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.

Gnuplot shows garbage when trying to save picture

When I input the following into the gnuplot window:
set xlabel "x"; set ylabel "y";
plot "rk1000.dat" with lines, "teor1000.dat" with lines
The result is a nice plot. However, when I attempt to save it as a .png file, the result is not so nice. After typing
set xlabel "x"; set ylabel "y"; set terminal png size 800,600;
plot "rk1000.dat" with lines, "teor1000.dat" with lines
the result is gnuplot spitting out garbage characters and doing nothing. Here's a screenshot:
How do I fix this? Not even an hour ago I had no problem saving my plots.
You can use set output in your script to make gnuplot redirect the output to a file:
set terminal png size 800,600
set output "plot.png"
plot "rk1000.dat" with lines, "teor1000.dat" with lines
If you are creating png images using gnuplot, the "pngcairo" terminal produces better-looking results. Try set terminal to see the list of available terminals.
Just save the output to a png file:
gnuplot script.gp > picture.png
Search the web for "redirection" if you want to know more.
you should plot first then set term
ex
"plot '../log/test_coverage_${atpg_mode}.log.tmp' title 'Ori ATPG' w lp lt 3 pt 9"
"set terminal png font \"/usr/share/fonts/liberation/LiberationSerif-Italic.ttf\" 9" ; # save the image as the png format
"set terminal png size 1000, 800" ; # save the image size as 800*1000
"set output '${REPORT_DIR}/Test_Coverage_Curve_${atpg_mode}.png'"
"replot"

Resources