0

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.

coderodde
  • 1,269
  • 4
  • 17
  • 34
  • Which version of gnuplot are you running? I would guess 5.4.x, since not all versions have the `cairolatex` option `png`. What is the image you are showing? The png you are getting or a screenshot from your LaTeX document? – theozh Sep 01 '22 at 08:42
  • gnuplot 5.4.4 Also, the file is the one generated by cairolatex. – coderodde Sep 01 '22 at 08:50
  • I don't have your data, but I only used the function and `cairolatex` with option `png` with gnuplot 5.4.0 under Win10. And I can reproduce your non-sense PNG. Seems to be some bug?! I don't know. However, I get some reasonable image if I use the option `cairolatex pdf`. Why not using PDF as I suggested in your other question https://stackoverflow.com/q/73510429/7295599 ? Can you only work with .eps or .png in your LaTeX system? – theozh Sep 01 '22 at 09:02
  • I tried further... What if you specify `set term cairolatex png standalone ...` or `set term cairolatex png input ...` Then I get useful PNGs, but I can't tell whether they will work for your LaTeX system. Read `help cairolatex` all the way down... it explains `standalone` and `input` options. – theozh Sep 01 '22 at 09:04
  • @theozh Tried `standalone` too. Looks good, but misses the axis labels and the legend texts. – coderodde Sep 01 '22 at 10:27
  • I thought the text will be added by LaTeX. You have to `set output "YourFile.tex"`, not with .png extension. And include the .tex into your LaTeX file. – theozh Sep 01 '22 at 10:32
  • @theozh Speaking of [my previous gnuplot question](https://stackoverflow.com/questions/73510429/gnuplot-does-not-draw-legend-lines-in-epslatex-terminal), I made a move towards solution but the y-axis label comes in double (with different fonts). Black magic, I reckon. (See the **Edit 2** section in the linked question.) – coderodde Sep 01 '22 at 10:45

1 Answers1

2

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.

binzo
  • 1,527
  • 1
  • 3
  • 13