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.
This commit is contained in:
Holger Vogt 2026-08-09 14:15:15 +02:00
parent c5cd68015c
commit c76219a37d
2 changed files with 10 additions and 5 deletions

View File

@ -298,7 +298,10 @@ void ft_gnuplot(double *xlims, double *ylims,
contours = has_contour_data(vecs); 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, if (!cp_getvar("gnuplot_terminal", CP_STRING,
terminal, sizeof(terminal))) { terminal, sizeof(terminal))) {
@ -626,8 +629,7 @@ void ft_gnuplot(double *xlims, double *ylims,
#if defined(__MINGW32__) || defined(_MSC_VER) #if defined(__MINGW32__) || defined(_MSC_VER)
/* for external fcn system() */ /* for external fcn system() */
// (void) sprintf(buf, "start /B wgnuplot %s -" , filename_plt); (void) snprintf(buf, sizeof(buf), "start /B wgnuplot -persist %s " , filename_plt);
(void) sprintf(buf, "start /B wgnuplot -persist %s " , filename_plt);
_flushall(); _flushall();
#else #else
/* for external fcn system() from LINUX environment */ /* for external fcn system() from LINUX environment */

View File

@ -278,8 +278,11 @@ void ft_pyplot(double *xlims, double *ylims,
fprintf(file, " _ax.grid(True, which='both')\n"); fprintf(file, " _ax.grid(True, which='both')\n");
if (xlims) if (xlims)
fprintf(file, " _ax.set_xlim(%e, %e)\n", xlims[0], xlims[1]); fprintf(file, " _ax.set_xlim(%e, %e)\n", xlims[0], xlims[1]);
if (ylims && !ylog) /* expand the limits a little (0.5%) to avoid double precision deviation on Windows */
fprintf(file, " _ax.set_ylim(%e, %e)\n", ylims[0], ylims[1]); 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"); fprintf(file, " _ax.legend()\n");
if (xlabel) { if (xlabel) {
text = cp_unquote(xlabel); text = cp_unquote(xlabel);