Search code examples
pdfgnuplot

Gnuplot: results differ when exporting to pdf and when plotting with qt


I am trying to plot a figure including the average of a distribution and its standard deviation using filledcurves with gnuplot. I get my figure by setting my terminal to pdf. However, when the points of my distribution do not belong to the displayed range of my y-axis, I noticed that the slope of my curve was wrong. This is even more surprising that I do get the right results when plotting my results first with qt and then exporting manually my figure to pdf.

Here is my minimal working example:

reset session

set terminal pdf
set output "~/MWE_results.pdf"

set yr[-100 : 100]

$Data <<EOD
40   0.000011           -0.002104            0.002126
20   0.240582           -4.877879            5.359043
10   0.926508           -9.378468           11.231484
5    4.794549          -19.298995           28.888093
2.5  84.993925        -6679.709571         6849.697422
1.25 6.220374        -3980.189531         3992.630280
EOD

set style fill transparent solid 0.1 

plot $Data u 1:2 w lp pt 7 lc rgb "black" ti "Mean value of my distribution", \
     $Data u 1:3:4 w filledcurves lc rgb "red" ti "Std devation"

unset output

unset term

This code gives me the following results (I circled the problematic slope): results I get when exporting directly to pdf

While the pdf file I get when plotting my results with qt and then exporting to pdf is the following (and is consistent with my data):

results I get when exporting directly when plotting with qt and then exporting to pdf

Does anyone have any idea what might be happening?

Thank you in advance for the help


Solution

  • As I mentioned in the comments, this is a really strange behaviour. I would say this is a terminal pdfcairo-specific bug.

    In your special case, the upper and lower borders for fill are always above and below y=0, respectively. So, a workaround which works in your case and in gnuplot 5.4.5 and 5.5.0 and with term pdfcairo is the following: separately fill your upper and lower border to y=0. The result will be like your second (expected) graph. Maybe there are better workarounds.

    plot $Data u 1:2 w lp pt 7 lc rgb "black" ti "Mean value of my distribution", \
         $Data u 1:3 w filledcurves y=0 lc rgb "red" ti "Std devation", \
         $Data u 1:4 w filledcurves y=0 lc rgb "red" notitle