Search code examples
svglatexgnuplot

Gnuplot svg terminal background box when using set ratio


I would like to include a gnuplot plot in LaTeX with \includesvg.

In gnuplot I basically just do:

set xrange [0:5]
set yrange [0:3]
set size ratio 0.5
set grid
set terminal svg dynamic
set output "diag.svg"
plot 1/0

This gives me a plot, however the svg has an empty box (multiple styles") in the background which stretches far above/below the plot. Apparently this is due to the line `set size ratio 0.5'.

In order for LaTeX to do proper scaling I need to get rid of this empty box and just have the actual diagram in it. How can I achieve this (in gnuplot)?

The created svg file can be downloaded here


Solution

  • The default canvas size for gnuplot's svg terminal is 600x480, which is a ratio of 1.25:1.00. The command set size ratio 0.5 requests a plot with aspect ratio 2:1. The mismatch between these two leads to blank space above and below the plot. If there were no axis and tic labels outside the plot boundary, the ideal size match would set aspect ratio of the canvas equal to that of the plot and set the margins to zero.

    However in order to leave space for the labels the margins must be larger than 0. You may want to reduce them from what the program selects by default. The proper amount of whitespace surrounding text is subjective, so adjust this to taste. You might start with set margins 2,1,2,1, which leaves slightly more space for the labels at the left and bottom of the plot boundary. It will look something like this:

      set term svg dynamic size 600,300
      set size ratio 0.5
      set margins 2,1,2,1
      plot ...
    

    enter image description here