Search code examples
latexgnuplotcairoplot

gnuplot cairolatex terminal produces strange results


I have this gnuplot script:

# set terminal cairolatex size 5.0cm,5.0cm color
# set output 'RatioVerbose.tex'

set grid
# set key font "Times New Roman,12"

set style line 1 \
    linecolor rgb '#a82828' \
    linetype 1 linewidth 3 \
    pointtype 5 pointsize 1.5

set xlabel "Entropy"
set ylabel "Actual work / theoretical work"
set xrange [-0.05:1.05]
set yrange [0:1.4]

f(x) = -1.3598 * x ** 2 + 1.3493 * x + 0.6590

set style line 2 lt 1 lw 3 linecolor rgb '#386dc2'

set terminal cairolatex png font ",12" fontscale 0.7 size 5.0cm,5.0cm

set output 'VerboseRatio.png'

plot 'RatioVerboseData.dat' with linespoints linestyle 1 notitle, \
      f(x) w l ls 2 title '$-1.3598x^2 + 1.3493x + 0.6590$'

# set terminal tikz size 5.0cm,5.0cm
# set terminal png size 700,700 enhanced font "Monospaced,13"
# set output 'RatioVerbose.png'

set output
replot
exit

... and it gives me:

Strange PNG file

I have been battling with the issue already for a quite of time, yet, alas, failed to find a working solution. Probably, I am missing some code in the gnuplot script.

Any help is much appreciated.

Edit

I added the actual PNG file generated by cairolatex.


Solution

  • This is not a bug.

    When using ‘cairolatex’ terminal, the filename specified by "set output" should be a LaTeX file, like following.

    set term cairolatex png input 
    set output "foo.tex"
    

    In this case, the LaTeX code is written to "foo.tex" and the plot image is written to "foo.png".

    In your script, a PNG file is set as an output file instead of a TeX file.

    set output 'VerboseRatio.png'
    

    This causes gnuplot to write the TeX code to a file named ‘VerboseRatio.png’ and at the same time to write the PNG image to the same file named ’VerboseRatio.png’. This results in the ‘VerboseRatio.png’ file having both PNG and Tex code in it.