gnuplot.c: improve scaling of y axis
This commit is contained in:
parent
2b72fbbc5e
commit
3ca1235602
|
|
@ -2,6 +2,7 @@ File: simple-meas-tran.sp
|
|||
* Simple .measurement examples
|
||||
* transient simulation of two sine signals with different frequencies
|
||||
vac1 1 0 DC 0 sin(0 1 1k 0 0)
|
||||
R1 1 0 100k
|
||||
vac2 2 0 DC 0 sin(0 1.2 0.9k 0 0)
|
||||
.tran 10u 5m
|
||||
*
|
||||
|
|
@ -31,6 +32,7 @@ vac2 2 0 DC 0 sin(0 1.2 0.9k 0 0)
|
|||
.control
|
||||
run
|
||||
plot v(1) v(2)
|
||||
gnuplot ttt i(vac1)
|
||||
meas tran tdiff TRIG v(1) VAL=0.5 RISE=1 TARG v(1) VAL=0.5 RISE=2
|
||||
meas tran tdiff TRIG v(1) VAL=0.5 RISE=1 TARG v(1) VAL=0.5 RISE=3
|
||||
meas tran tdiff TRIG v(1) VAL=0.5 RISE=1 TARG v(1) VAL=0.5 FALL=1
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab
|
|||
{
|
||||
FILE *file, *file_data;
|
||||
struct dvec *v, *scale = NULL;
|
||||
double xval, yval;
|
||||
double xval, yval, extrange;
|
||||
int i, numVecs, linewidth, err;
|
||||
bool xlog, ylog, nogrid, markers;
|
||||
char buf[BSIZE_SP], pointstyle[BSIZE_SP], *text, plotstyle[BSIZE_SP];
|
||||
|
|
@ -47,6 +47,15 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab
|
|||
fprintf(cp_err, "Error: too many vectors for gnuplot.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (fabs((ylims[1]-ylims[0])/ylims[0]) < 1.0e-6) {
|
||||
fprintf(cp_err, "Error: range min ... max too small for using gnuplot.\n");
|
||||
fprintf(cp_err, " Consider plotting with offset %g.\n", ylims[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
extrange = 0.05 * (ylims[1] - ylims[0]);
|
||||
|
||||
if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth))
|
||||
linewidth = 1;
|
||||
if (linewidth < 1) linewidth = 1;
|
||||
|
|
@ -60,7 +69,6 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab
|
|||
markers = FALSE;
|
||||
}
|
||||
|
||||
|
||||
/* Make sure the gridtype is supported. */
|
||||
switch (gridtype) {
|
||||
case GRID_LIN:
|
||||
|
|
@ -118,6 +126,8 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab
|
|||
if (xlog) {
|
||||
fprintf(file, "set logscale x\n");
|
||||
if (xlims)
|
||||
/* fprintf(file, "set xrange [%1.0e:%1.0e]\n",
|
||||
pow(10, floor(log10(xlims[0]))), pow(10, ceil(log10(xlims[1])))); */
|
||||
fprintf(file, "set xrange [%e:%e]\n", xlims[0], xlims[1]);
|
||||
} else {
|
||||
fprintf(file, "unset logscale x \n");
|
||||
|
|
@ -127,11 +137,12 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab
|
|||
if (ylog) {
|
||||
fprintf(file, "set logscale y \n");
|
||||
if (ylims)
|
||||
fprintf(file, "set yrange [%e:%e]\n", ylims[0], ylims[1]);
|
||||
fprintf(file, "set yrange [%1.0e:%1.0e]\n",
|
||||
pow(10, floor(log10(ylims[0]))), pow(10, ceil(log10(ylims[1]))));
|
||||
} else {
|
||||
fprintf(file, "unset logscale y \n");
|
||||
if (ylims)
|
||||
fprintf(file, "set yrange [%e:%e]\n", ylims[0], ylims[1]);
|
||||
fprintf(file, "set yrange [%e:%e]\n", ylims[0] - extrange, ylims[1] + extrange);
|
||||
}
|
||||
|
||||
fprintf(file, "#set xtics 1\n");
|
||||
|
|
@ -160,7 +171,8 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab
|
|||
perror(filename);
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(file, "set format y \"%%g\"\n");
|
||||
fprintf(file, "set format x \"%%g\"\n");
|
||||
fprintf(file, "plot ");
|
||||
i = 0;
|
||||
|
||||
|
|
@ -178,8 +190,10 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab
|
|||
fprintf(file, "set terminal push\n");
|
||||
fprintf(file, "set terminal postscript eps color\n");
|
||||
fprintf(file, "set out \'%s.eps\'\n", filename);
|
||||
|
||||
fprintf(file, "replot\n");
|
||||
fprintf(file, "set term pop\n");
|
||||
|
||||
fprintf(file, "replot\n");
|
||||
|
||||
(void) fclose(file);
|
||||
|
|
@ -195,7 +209,7 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab
|
|||
yval = isreal(v) ?
|
||||
v->v_realdata[i] : realpart(v->v_compdata[i]);
|
||||
|
||||
fprintf(file_data, "% e % e ", xval, yval);
|
||||
fprintf(file_data, "%e %e ", xval, yval);
|
||||
}
|
||||
fprintf(file_data, "\n");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue