Ilya Zakharevich on Fri, 9 Oct 1998 18:24:31 -0400 (EDT)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Improved variant of patch to plot() (fwd)


ilya writes:
>From ilya Fri Oct  9 17:52:27 1998
Subject: Improved variant of patch to plot()
To: pari-dev@list.cr.yp.to (Developers Pari)
Date: Fri, 9 Oct 1998 17:52:27 -0400 (EDT)
X-Mailer: ELM [version 2.5 PL0b1]
Content-Length: 4281      

When inspecting the output of plot(), I found that the output of the
labels was completely screwed up, which an addition to visual clutter
misplaces data points where function takes the minimal values.

Here is the improved variant of the previous patch which puts the
label in "%g" format, and in correct places.

Now 
	plot(x=2,4,6+sin(x^3)) 
outputs:

        7 "x''''''''''_"x''''''''"_''''''"_'''''"'''''"''''__'''__'''"'''x
          | x            _      "       x :    x x     _   ::   ::       :
          |  x       "         _   _       :   : :   " :  :  : :  : _ _ :|
          |   _     x     x            _   x  :   :  :  : _  : :  : : : :|
          |                   _     _         x   x :   _ :  " "  _:   :"|
          |    "_  "       "          _     _       "    :         :   : |
          |      x"         ""       "       "     "     "    x    "   " |
          |                                                              |
          |                                                              |
          |                                                              |
          |                                                              |
          |                                                              |
          |                                                              |
          |                                                              |
          |                                                              |
          |                                                              |
          |                                                              |
          |                                                              |
          |                                                              |
          |                                                              |
          |                                                              |
        0 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
          2                                                              4


--- ./pari-2.0.11.beta/src/graph/plotport.c~	Thu Oct  8 02:10:20 1998
+++ ./pari-2.0.11.beta/src/graph/plotport.c	Fri Oct  9 17:42:59 1998
@@ -47,7 +47,7 @@ PARI_plot pari_plot, pari_psplot;
 #define XX_LOWER '.'
 #define FF1 '_'
 #define FF2 'x'
-#define FF3 '*'
+#define FF3 '"'
 #define PICT(j) ((j) % 3 ? ((j) % 3 == 2 ? FF3 : FF2) : FF1)
 
 void
@@ -55,7 +55,7 @@ plot(entree *ep, GEN a, GEN b, char *ch)
 {
   long av = avma, av2,limite,jz,j,i,sig;
   GEN p1,p2,ysml,ybig,x,diff,dyj,dx,y[ISCR+1];
-  char scr[ISCR+1][JSCR+1], z;
+  char scr[ISCR+1][JSCR+1], z, jprev, jnew;
 
   sig=gcmp(b,a); if (!sig) return;
   if (sig<0) { x=a; a=b; b=x; }
@@ -94,10 +94,39 @@ plot(entree *ep, GEN a, GEN b, char *ch)
   for (i=1; i<=ISCR; i++)
   {
     scr[i][jz]=z; j=3+gtolong(gmul(gsub(y[i],ysml),dyj));
-    scr[i][j/3] = PICT(j); avma=av2;
+    jnew = j/3;
+    if (i > 1) {
+	int i_up, i_down,  mid = (jprev + jnew)/2, up, down;
+	int domid = 0, jmid;
+	
+	/* If the gap is 1, leave it as it is. */
+	if (jprev < jnew - 2) {
+	    i_up = i;
+	    i_down = i - 1;
+	    up = jnew - 1;
+	    down = jprev + 1;
+	    domid = 1;
+	} else if (jnew < jprev - 2) {
+	    i_up = i - 1;
+	    i_down = i;
+	    down = jnew + 1;
+	    up = jprev - 1;
+	    domid = 1;
+	}
+	if (domid) {
+	    while (down <= mid) {
+		scr[i_down][down++] = ':';
+	    }
+	    while (up > mid) {
+		scr[i_up][up--] = ':';
+	    }
+	}
+    }
+    scr[i][jnew] = PICT(j); avma=av2;
+    jprev = jnew;
   }
   p1=cgetr(3); gaffect(ybig,p1); pariputc('\n');
-  pariputsf(" %8.3e",rtodbl(p1));
+  pariputsf(" %8.3g ",rtodbl(p1));
   for (i=1; i<=ISCR; i++) pariputc(scr[i][JSCR]);
   pariputc('\n');
   for (j=(JSCR-1); j>=2; j--)
@@ -107,12 +136,12 @@ plot(entree *ep, GEN a, GEN b, char *ch)
     pariputc('\n');
   }
   p1=cgetr(3); gaffect(ysml,p1);
-  pariputsf("%8.3e",rtodbl(p1));
+  pariputsf(" %8.3g ",rtodbl(p1));
   for (i=1; i<=ISCR; i++)  pariputc(scr[i][1]);
   pariputc('\n');
   p1=cgetr(3); gaffect(a,p1);
   p2=cgetr(3); gaffect(b,p2);
-  pariputsf("%8s %8.3e %44s %8.3e\n"," ",rtodbl(p1)," ",rtodbl(p2));
+  pariputsf("%10s%-8.3g%*s%8.3g\n"," ",rtodbl(p1),ISCR-16," ",rtodbl(p2));
   pop_val(ep); avma=av;
 }