File: plot_demo.i

package info (click to toggle)
yorick-yutils 1.3.0-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 604 kB
  • ctags: 17
  • sloc: makefile: 105; python: 12
file content (259 lines) | stat: -rw-r--r-- 7,237 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
 * plot_demo.i --
 *
 *	Demonstration of routines in "plot.i".
 *	Provides routines: plot_demo, plot_demo1, plot_demo2.
 *
 * Copyright (c) 1996, Eric THIEBAUT (thiebaut@obs.univ-lyon1.fr, Centre de
 *	Recherche Astrophysique  de Lyon, 9 avenue Charles  Andre,
 *	F-69561 Saint Genis Laval Cedex).
 *
 * This program is free software; you can redistribute it and/or  modify it
 * under the terms of the GNU General Public License  as  published  by the
 * Free Software Foundation; either version 2 of the License,  or  (at your
 * option) any later version.
 *
 * This program is distributed in the hope  that  it  will  be  useful, but
 * WITHOUT  ANY   WARRANTY;   without   even   the   implied   warranty  of
 * MERCHANTABILITY or  FITNESS  FOR  A  PARTICULAR  PURPOSE.   See  the GNU
 * General Public License for more details (to receive a  copy  of  the GNU
 * General Public License, write to the Free Software Foundation, Inc., 675
 * Mass Ave, Cambridge, MA 02139, USA).
 *
 * History:
 *	$Id: plot_demo.i,v 1.1.1.1 2007/12/11 23:55:14 frigaut Exp $
 *	$Log: plot_demo.i,v $
 *	Revision 1.1.1.1  2007/12/11 23:55:14  frigaut
 *	Initial Import - yorick-yutils
 *	
 *	Revision 1.2  2002/11/14 11:20:52  eric
 *	 - changed paths in require calls
 *
 */

require, "plot.i";
require, Y_SITE+"include/random.i";

func plot_demo {plot_demo1; plot_demo2;}

func plot_demo1
{
  /*
   * Select an eventually new window and choose "work" style.
   */
  win = max(0, current_window());
  window, win, wait=1, style="work.gs";
  limits;
  animate, 0;
  pldefault, font="helveticaBI", width=5, height=10, marks=0;

  /*
   * Some data.
   */
  x= span(0., 2., 500);
  y= sin(-pi*exp(x))*exp(-x);
  xp= x(15::30);
  yp= y(15::30);
  dx= 0.05;
  dy= 0.05 + yp/5.;	// RSB ~ 5
  xn= dx*random_n(dimsof(xp));
  yn= dy*random_n(dimsof(yp));

  write, " - true model and data points (in green)";
  plg, y, x;
  plp, yp+yn, xp+xn, color="green";
  fma;
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;

  write, " - data points (in green) with error bars (in red)";
  plg, y, x;
  plp, yp+yn, xp+xn, dx=dx, dy=dy, ticks=0, color="red", symbol=0;
  plp, yp+yn, xp+xn, color="green";
  fma;
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;

  write, " - data points with error bars and ticks (in blue)";
  plg, y, x;
  plp, yp+yn, xp+xn, dx=dx, dy=dy, ticks=3, color="blue";
  fma;
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;

  write, " - data points with error bars, ticks and symbol (in green)";
  plg, y, x;
  plp, yp+yn, xp+xn, dx=dx, dy=dy, ticks=3, symbol=5, size=1.5, width=1,
    color="green";
  fma;
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;

  write, " - data points with various symbols and colors";
  plg, y, x;
  colors= ["red", "green", "blue", "magenta", "cyan", "yellow"];
  for (i=1; i<=numberof(colors);i++) {
    xn= dx*random_n(dimsof(xp));
    yn= dy*random_n(dimsof(yp));
    plp, yp+yn, xp+xn, symbol=i-1, size=1.5, color=colors(i);
  }
  fma;
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;

  write, " - histograms with different justification (plh)";
  pldefault, font="helveticaBI", width=1, height=10, marks=0;
  plh, y(::10)-.1, x(::10), just=1, marks=0, color="blue";
  plh, y(::10), x(::10), just=2, marks=0;
  plh, y(::10)+.1, x(::10), just=3, marks=0, color="cyan";
  fma;
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;

}

func plot_demo2
{
  
  write, "WARNING - demo under construction ...";
  return;

  
  local alt, az;
  x= span(-1, 1, 30)(,-:1:30);
  y= transpose(x);
  a= abs(x, y);
  a= exp(-32.*a^2);
  a= a + .3 * roll(a, [5,-5]) - .7 * roll(a, [-5,-10]);

  /*
   * Select an eventually new window and choose "nobox" style.
   */
  win = max(0, current_window());
  window, win, wait=1, style="nobox.gs";
  palette, "rainbow.gp";
  limits;
  animate, 1;
  pldefault, font="helveticaBI", height=10;

  write, " - deformation of a surface mesh";
  pl3s, a, y, x, edges=1, fill=1, axis=1;
  fma;
  q= [100, 60, 45, 35, 25, 20, 15, 12, 9, 7, 6, 5];
  for (k = 1; k <= numberof(q); k++) {
    z= x+1i*y;
    z= q(k)*z/(q(k)+z*z);
    xx= z.re;
    yy= z.im;
    pl3s, a, yy, xx, edges=1, fill=1, axis=1;
    fma;
  }
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;

  write, " - surface mesh as wireframe (fill=0 or nil)";
  pl3s, a, yy, xx, edges=1, fill=0, axis=1, box=1;
  fma;
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;

  write, " - surface mesh filled with brightness (fill=1)";
  pl3s, a, yy, xx, edges=1, fill=1, axis=1, box=1;
  fma;
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;

  write, " - surface mesh shaded (fill=2)";
  pl3s, a, yy, xx, edges=1, fill=2, axis=1, box=1;
  fma;
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;

  write, " - rotation of the point of view";
  step= 20;
  az= 35.;
  alt= 35.;
  while (az <= 360.) {
    for (x=0; x<=360; x+=step) {
      pl3s, a, yy, xx, az=az, alt=alt+x, box=1, edges=1, fill=1, axis=0;
      fma;
    }
    for (x=step; x<=90; x+=step) {
      pl3s, a, yy, xx, az=az+x, alt=alt, box=1, edges=1, fill=1, axis=0;
      fma;
    }
    az += 90.;
  }
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;

  /*
   * Restore plot defaults.
   */
  animate, 0;

  /*
   * 2-D surface plot.
   */
  window, win, wait=1, style="work.gs";
  pldefault, width=1;
  write, " - filled mesh with contour (pls routine)";
  pls, a, cbar=1,  nlevs=10, xtitle="abscissa", ytitle="ordinate",
    title="Example of PLS routine", font="timesBI", height=14, marks=0;
  fma;
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;
  write, " - filled mesh with contour (pls routine)";
  pls, a, yy, xx, cbar=1,  nlevs=10, xtitle="abscissa", ytitle="ordinate",
    title="Example of PLS routine", font="timesBI", height=14, marks=0;
  fma;
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;

}

func plot_demo3(step)
{
  local alt, az;
  x=span(-1, 1, 40)(,-:1:30);
  y=span(-2, 4, 30)(-:1:40,);
  z=sin(x*x+y*x);

  /*
   * Select an eventually new window and choose "nobox" style.
   */
  win = max(0, current_window());
  window, win, wait=1, style="nobox.gs";
  palette, "rainbow.gp";
  limits;
  animate, 1;
  pldefault, font="helveticaBI", height=10;

  write, " - rotation of the point of view";
  if (!step) {
    step = 20;
  }
  az= 35.;
  alt= 35.;
  while (az <= 360.) {
    for (a=0; a<=360; a+=step) {
      pl3s, z, y, x, az=az, alt=alt+a, box=1, edges=1, fill=1, axis=1;
      fma;
      //rdline, prompt="hit Enter to continue";
     }
    for (a=step; a<=90; a+=step) {
      pl3s, z, y, x, az=az+a, alt=alt, box=1, edges=1, fill=1, axis=1;
      fma;
      //rdline, prompt="hit Enter to continue";
    }
    az += 90;
  }
  if (strtok(rdline(prompt="hit Enter to continue, Q to quit"))(1)=="q")
    return;

  /*
   * Restore plot defaults.
   */
  animate, 0;

}