1
votes

I am having problem with cairolatex terminal in gnuplot.

I am setting my terminal as follows:

et terminal cairolatex eps rounded size 5,3 font ',17' standalone background "#9e9e9e"

The background is set up properly outside of the plot, but remains white inside of the plot area. I have also tried "transparent" with the same problem. Basically, the automatically generated file filename-inc which is included in the latex is incorrect.

In the attached picture you see grey background of the beamer slide with include pdf generated with gnuplot via cairolatex.

It drives me crazy.

Edit: Here is minimal code.

#!/usr/local/bin/gnuplot

set terminal cairolatex eps rounded size 5,3 font ',17' standalone background "#9e9e9e"

set output "graph.tex"

set xlabel "x $x$ [$\\mu$s]"
set ylabel 'Spot size $\sigma$ [\AA]'
set yrange [-1.1:1.1]

#plot
plot sin(x) notit lw 5, \
    cos(x) notit lw 50 lc rgb "#77ff0000", \
    .5*sin(.9*x) notit lw 30 lc rgb "#200000ff"

unset output

Just run gnuplot on the config file followed by pdflatex graph.tex

I am using gnuplot 5.4 patch 2 on Mac via MacPorts.

Thank you.

Radovan

enter image description here

3
Can you make a minimal reproducible example so we can reproduce the issue?samcarter_is_at_topanswers.xyz
Example added. Labels are there just to test latex typesetting. Note, that the same issue is present in "transparent" is used. It seems, set terminal epslatex rounded size 5,3 font ',17' standalone nobackground works, but it does not honour line transparency. Same issues prevail when input is used instead standalone. -- RadovanRadovan Urban

3 Answers

4
votes

Partial explanation why using lc rgb "#77ff0000" causes problems

The color specification rgb "#77ff0000" is correct gnuplot ARGB syntax for partially transparent red. The original plot commands should work as intended for all terminal types that support transparency. Unfortunately the eps variant of cairolatex is not one of those because the PostScript language itself does not support transparency. Some graphics layer underneath (not sure whether it's cairo or latex in this case) tries to dummy it up by substituting a bit-by-bit approximation for that part of the graphic but does a very poor job of it.

The solution is to avoid any variant of PostScript for output that uses an alpha channel. You should be OK with either of

  set term cairolatex pdf
  set term tikz
0
votes

I can reproduce your issue, and I don't quite understand why the gray background is partially overlaid with white… anyway, there is a workaround: Instead of fiddling with the background option of cairolatex, you can place a rectangle with the desired colour:

set object rectangle from screen 0,0 to screen 1,1 behind fc "#9e9e9e"

Surprisingly, this is creating another issue: For some reason, the tic labels become hidden. In order to correct for that, one has to specify set tics front.

Because you are running the output through pdflatex, there should be no need to create eps, but you can use pdf directly instead. Therefore, the full code would be:

reset session

set terminal cairolatex rounded size 5,3 font ',17' standalone 
set output "graph.tex"

set xlabel "x $x$ [$\\mu$s]"
set ylabel 'Spot size $\sigma$ [\AA]'
set yrange [-1.1:1.1]
set tics front

set object 1 rectangle from screen 0,0 to screen 1,1 behind fc "#9e9e9e"

#plot
plot sin(x) notit lw 5, \
    cos(x) notit lw 50 lc rgb "#77ff0000", \
    .5*sin(.9*x) notit lw 30 lc rgb "#200000ff"

unset out

enter image description here

0
votes

Setting lc seems to cause the white rectangle. If one examines the eps, all the curves with this line colour are included as a pixelated image instead of a vector image.

You could works around the problem like this:

#!/usr/local/bin/gnuplot

set terminal cairolatex eps rounded size 5,3 font ',17' standalone background "#9e9e9e"

set output "graph.tex"

set xlabel "x $x$ [$\\mu$s]"
set ylabel 'Spot size $\sigma$ [\AA]'
set yrange [-1.1:1.1]

#plot
plot cos(x) notit lw 50 lt 7 , \
     sin(x) notit lw 5 lt 1, \
     .5*sin(.9*x) notit lw 30 lt 14

unset output

enter image description here