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