From c76219a37d471c38fc22f804973f1b9f4bb201e6 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sun, 9 Aug 2026 14:15:15 +0200 Subject: [PATCH] pyplot: If on MSVC the top graph limit is slightly less (due to double precision deviations) than the vector contents, the graph will not be plotted in this area. Therefore extend the limits a bit (0.5%). Gnuplot: Use snprintf instead of sprintf. Reduce limits extension to 0.005. --- src/frontend/plotting/gnuplot.c | 8 +++++--- src/frontend/plotting/pyplot.c | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/frontend/plotting/gnuplot.c b/src/frontend/plotting/gnuplot.c index 662edb43f..b7b17f5b5 100644 --- a/src/frontend/plotting/gnuplot.c +++ b/src/frontend/plotting/gnuplot.c @@ -298,7 +298,10 @@ void ft_gnuplot(double *xlims, double *ylims, contours = has_contour_data(vecs); } - extrange = 0.05 * (ylims[1] - ylims[0]); + if (ylims) + extrange = 0.005 * (ylims[1] - ylims[0]); + else + extrange = 0.; if (!cp_getvar("gnuplot_terminal", CP_STRING, terminal, sizeof(terminal))) { @@ -626,8 +629,7 @@ void ft_gnuplot(double *xlims, double *ylims, #if defined(__MINGW32__) || defined(_MSC_VER) /* for external fcn system() */ - // (void) sprintf(buf, "start /B wgnuplot %s -" , filename_plt); - (void) sprintf(buf, "start /B wgnuplot -persist %s " , filename_plt); + (void) snprintf(buf, sizeof(buf), "start /B wgnuplot -persist %s " , filename_plt); _flushall(); #else /* for external fcn system() from LINUX environment */ diff --git a/src/frontend/plotting/pyplot.c b/src/frontend/plotting/pyplot.c index 16dd1d3ce..cc86313ce 100644 --- a/src/frontend/plotting/pyplot.c +++ b/src/frontend/plotting/pyplot.c @@ -278,8 +278,11 @@ void ft_pyplot(double *xlims, double *ylims, fprintf(file, " _ax.grid(True, which='both')\n"); if (xlims) fprintf(file, " _ax.set_xlim(%e, %e)\n", xlims[0], xlims[1]); - if (ylims && !ylog) - fprintf(file, " _ax.set_ylim(%e, %e)\n", ylims[0], ylims[1]); + /* expand the limits a little (0.5%) to avoid double precision deviation on Windows */ + if (ylims && !ylog) { + double extrange = (ylims[1] - ylims[0]) * 0.005; + fprintf(file, " _ax.set_ylim(%e, %e)\n", ylims[0] - extrange, ylims[1] + extrange); + } fprintf(file, " _ax.legend()\n"); if (xlabel) { text = cp_unquote(xlabel);