3
Permission granted to copy and distribute this work provided that this
6
Python interface bindings
7
Written by: interran@uluru.Stanford.EDU (John Interrante)
8
et@appl-math.tu-muenchen.de (Thomas Schwaller)*/
10
/* Additional changes under LGPL by Geoffrey Furnish and Alan W. Irwin */
12
/* Rules for translating C PLplot function calls into Python PLplot:
13
- All names are the the same (plot3d modified to plplot3d for uniformity), but
14
now for uniformity with C API change back to plot3d---AWI.
15
- C arrays are replaced by Python matrices or objects which can be
16
converted to matrices.
17
- Array and Matrix lengths are eliminated since matrices know how long they are.
18
- Output parameters are replaced by function return values or tuples.
20
Thanxs to Jim Fulton, James Hugunin, Konrad Hinsen and all the other people in the
21
Python Matrix SIG for the stimulating talks and the same spirit of mind!
25
#include "plplot/plmodule.h"
27
/*static*/ int pl_PyArray_AsFloatArray(PyObject **op, PLFLT **pitems,
31
mp = (PyArrayObject *)
32
PyArray_ContiguousFromObject (*op, PyArray_PLFLT, 0, 1);
34
*pitems =(PLFLT*) (mp->data);
35
*pn = mp->dimensions[0];
40
/*static*/ int pl_PyArray_AsIntArray(PyObject **op, PLINT **pitems, PLINT *pn)
43
mp = (PyArrayObject *) PyArray_ContiguousFromObject (*op, PyArray_INT, 0, 1);
45
*pitems =(PLINT*) (mp->data);
46
*pn = mp->dimensions[0];
51
/* Thanxs to James Hugunin for helping me with that! */
53
/*static*/ int pl_PyArray_AsFloatMatrix (PyObject **op, PLINT* m, PLINT* n, PLFLT*** pitems)
58
mp = (PyArrayObject *) PyArray_ContiguousFromObject (*op, PyArray_PLFLT, 2, 2);
60
*m = mp->dimensions[0];
61
*n = mp->dimensions[1];
63
size = *n * sizeof(PLFLT);
64
if (!(dpp = PyMem_NEW(char*, *m))) {
71
*pitems = (PLFLT**) dpp;
76
/* Convert a Python list of strings to a C array. Code copied from stdwinmodule.c. */
78
/*static*/ int pl_PyList_AsStringArray(PyObject *list, char ***pitems, int *pn)
82
n = PyList_Size(list);
83
items = PyMem_NEW(char*, n + 1);
88
for (i = 0; i < n; i++) {
89
PyObject *item = PyList_GetItem(list, i);
90
if (!PyString_Check(item)) {
91
PyErr_SetString(PyExc_TypeError, "list of strings expected");
94
items[i] = PyString_AsString(item);
96
items[n] = NULL; /* Obey convention of NULL-terminated argv */
102
/* Store a C array back into a Python list of strings. Code copied from stdwinmodule.c. */
104
/*static*/ int pl_PyList_SetFromStringArray(PyObject *list, char **items, int n)
106
int i, oldsize = PyList_Size(list);
108
if (n == oldsize) return 1;
109
newlist = PyList_New(n);
110
for (i = 0; i < n && newlist != NULL; i++) {
112
PyObject *item = PyString_FromString(items[i]);
117
PyList_SetItem(newlist, i, item);
119
/* plParseOpts is buggy; it can return NULLs in the
120
middle of the argument list. We still have n - i args
121
left to store, so skip over the NULL. */
126
if (newlist == NULL) return 0;
127
PyList_SetSlice(list, 0, oldsize, newlist);
132
static char doc_pladv[] = "Advance to subpage \"page\", or to the next one if \"page\" = 0";
134
static PyObject * pl_adv(PyObject *self, PyObject *args)
137
TRY (PyArg_ParseTuple(args, "i", &page));
143
static char doc_plarrows[] = "simple arrow plotter";
145
static PyObject * pl_arrows(PyObject *self, PyObject *args)
147
PLFLT *u, *v, *x, *y, scale, dx, dy;
148
PLINT un, vn, xn, yn;
149
PyObject *uop, *vop, *xop, *yop;
150
TRY (PyArg_ParseTuple(args, PL_ARGS("OOOOddd", "OOOOfff"),
151
&uop, &vop, &xop, &yop, &scale, &dx, &dy));
152
TRY (pl_PyArray_AsFloatArray(&uop, &u, &un));
153
TRY (pl_PyArray_AsFloatArray(&vop, &v, &vn));
154
TRY (pl_PyArray_AsFloatArray(&xop, &x, &xn));
155
TRY (pl_PyArray_AsFloatArray(&yop, &y, &yn));
156
if ((un != vn) || (vn != xn) || (xn != yn)) {
157
PyErr_SetString(PyExc_ValueError, "first 4 arguments should have the same length");
164
plarrows(u, v, x, y, un, scale, dx, dy);
173
static char doc_plaxes[]=" This functions similarly to plbox() except that the origin of the axes is placed at the user-specified point (x0, y0)";
175
static PyObject * pl_axes(PyObject *self, PyObject *args)
177
PLFLT x0, y0, xtick, ytick;
179
const char *xopt, *yopt;
180
TRY (PyArg_ParseTuple(args, PL_ARGS("ddsdisdi", "ffsfisfi"), &x0, &y0, &xopt, &xtick,
181
&nxsub, &yopt, &ytick, &nysub));
182
plaxes(x0, y0, xopt, xtick, nxsub, yopt, ytick, nysub);
187
static char doc_plbin[]="Plot a histogram using x to store data values and y to store frequencies";
189
static PyObject * pl_bin(PyObject *self, PyObject *args)
191
PLINT nbin, center, ylen;
194
TRY (PyArg_ParseTuple(args, "OOi", &xop, &yop, ¢er));
195
TRY (pl_PyArray_AsFloatArray(&xop, &x, &nbin));
196
TRY (pl_PyArray_AsFloatArray(&yop, &y, &ylen));
198
PyErr_SetString(PyExc_ValueError, "args 1 and 2 should have the same length");
203
plbin(nbin, x, y, center);
210
static char doc_plbop[]="Start new page. Should only be used with pleop()";
212
static PyObject * pl_bop(PyObject *self, PyObject *args)
214
TRY (PyArg_ParseTuple(args, ""));
220
static char doc_plbox[]="This draws a box around the current viewport";
222
static PyObject * pl_box(PyObject *self, PyObject *args)
224
const char *xopt, *yopt;
227
TRY (PyArg_ParseTuple(args, PL_ARGS("sdisdi", "sfisfi"),
228
&xopt, &xtick, &nxsub, &yopt, &ytick, &nysub));
229
plbox(xopt, xtick, nxsub, yopt, ytick, nysub);
234
static char doc_plcalc_world[]="Calculate world coordinates";
236
static PyObject * pl_calc_world(PyObject *self, PyObject *args)
238
PLFLT rx, ry, wx, wy;
240
TRY (PyArg_ParseTuple(args, PL_ARGS("dd", "ff"), &rx, &ry));
241
plcalc_world(rx, ry, &wx, &wy, &window);
242
return Py_BuildValue(PL_ARGS("(ddi)", "(ffi)"), wx, wy, window);
246
static char doc_plbox3[]="This is the 3-d analogue of plbox()";
248
static PyObject * pl_box3(PyObject *self, PyObject *args)
250
const char *xopt, *xlabel, *yopt, *ylabel, *zopt, *zlabel;
251
PLFLT xtick, ytick, ztick;
252
PLINT nsubx, nsuby, nsubz;
253
TRY (PyArg_ParseTuple(args, PL_ARGS("ssdissdissdi", "ssfissfissfi"),
254
&xopt, &xlabel, &xtick, &nsubx, &yopt, &ylabel, &ytick, &nsuby,
255
&zopt, &zlabel, &ztick, &nsubz));
256
plbox3(xopt, xlabel, xtick, nsubx, yopt, ylabel, ytick, nsuby, zopt, zlabel, ztick, nsubz);
261
static char doc_plcol0[]="Set color, map 0. Argument is integer between 0 and 15";
263
static PyObject * pl_col0(PyObject *self, PyObject *args)
266
TRY (PyArg_ParseTuple(args, "i", &icol0));
272
static char doc_plcol1[]="Set color, map 1. Argument is a float between 0. and 1";
274
static PyObject * pl_col1(PyObject *self, PyObject *args)
277
TRY (PyArg_ParseTuple(args, PL_ARGS("d", "f"), &col1));
283
/* superseded by plcont
284
static char doc_plcont_ts[]="Draws a contour plot from data in f(nx,ny). Is just a front-end to plfcont, with a particular choice for f2eval and f2eval_data";
286
static void pypltr(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer data)
288
PyObject *ret, *value;
289
value = Py_BuildValue(PL_ARGS("(dd)", "(ff)"), x, y);
290
ret = PyEval_CallObject( (PyObject*) data, value);
291
PyArg_ParseTuple(ret, PL_ARGS("dd", "ff"), tx, ty);
296
static PyObject * pl_cont_ts(PyObject *self, PyObject *args)
298
PLINT nx, ny, kx, lx, ky, ly, nlevel;
300
PyObject *op, *levelop, *f;
301
TRY (PyArg_ParseTuple(args, "OiiiiOO!", &op, &kx, &lx, &ky, &ly, &levelop,
302
&PyFunction_Type, &f));
303
TRY (pl_PyArray_AsFloatMatrix(&op, &nx, &ny, &z));
304
TRY (pl_PyArray_AsFloatArray(&levelop, &clevel, &nlevel));
305
plcont(z, nx, ny, kx, lx, ky, ly, clevel, nlevel, pypltr, f);
309
if (PyErr_Occurred()) {
310
PyErr_SetString(PyExc_RuntimeError, "Check your plotter function!");
318
static char doc_plcont2[]="Draws a contour plot from data in f(nx,ny). Is just a front-end to plfcont, with a particular choice for f2eval and f2eval_data";
321
pyt0(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data)
323
/* printf( "evaluating tr0(%lf,%lf)\n", x, y );
328
/* static int pl_pymateval_modx, pl_pymateval_mody; */
330
/*--------------------------------------------------------------------------*\
333
* Does a lookup from a 2d function array. Array is of type (PLFLT **),
334
* and is column dominant (normal C ordering).
335
\*--------------------------------------------------------------------------*/
338
pyf2eval2(PLINT ix, PLINT iy, PLPointer plf2eval_data)
341
PLfGrid2 *grid = (PLfGrid2 *) plf2eval_data;
343
/* printf( "In pyf2eval2(%d,%d)=%lf\n",
344
ix, iy, grid->f[ix][iy] );
349
value = grid->f[ix][iy];
354
static PyObject * pl_cont2(PyObject *self, PyObject *args)
356
PLINT nx, ny, kx, lx, ky, ly, nlevel;
358
PyObject *op, *levelop;
361
/* printf( "In Geoff's plcont2.\n" );*/
363
TRY( PyArg_ParseTuple( args, "OiiiiO",
364
&op, &kx, &lx, &ky, &ly, &levelop ) );
365
TRY (pl_PyArray_AsFloatMatrix(&op, &nx, &ny, &z));
366
TRY (pl_PyArray_AsFloatArray(&levelop, &clevel, &nlevel));
368
/* printf( "nx=%d ny=%d kx=%d lx=%d ky=%d ly=%d\n",
369
nx, ny, kx, lx, ky, ly );
370
printf( "nlevel=%d\n", nlevel );
371
for( i=0; i < nlevel; i++ )
372
printf( "level[%d] = %lf\n", i, clevel[i] );
374
for( i=kx-1; i < lx; i++ ) {
376
for( j=ky-1; j < ly; j++ ) {
377
printf( " data(%d,%d) = %lf\n", i, j, z[i][j] );
383
/* plcont(z, nx, ny, kx, lx, ky, ly, clevel, nlevel, pyt0, NULL );*/
384
plcontf( pyf2eval2, (PLPointer) &grid,
385
nx, ny, kx, lx, ky, ly, clevel, nlevel,
390
if (PyErr_Occurred()) {
391
PyErr_SetString(PyExc_RuntimeError, "Check your plotter function!");
399
static char doc_plcont[]="Draws a contour plot using the function evaluator f2eval and data stored by way of the f2eval_data pointer. This allows arbitrary organizations of 2d array data to beused.";
401
void plfcont(PLFLT (*f2eval) (PLINT, PLINT, PLPointer),
402
PLPointer f2eval_data,
403
PLINT nx, PLINT ny, PLINT kx, PLINT lx,
404
PLINT ky, PLINT ly, PLFLT *clevel, PLINT nlevel,
405
void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer),
406
PLPointer pltr_data);
409
static char doc_plcpstrm[]="Copies state parameters from the reference stream to the current stream";
411
static PyObject * pl_cpstrm(PyObject *self, PyObject *args)
414
TRY (PyArg_ParseTuple(args, "ii", &iplsr, &flags));
415
plcpstrm(iplsr, flags);
420
static char doc_pldid2pc[]="Converts input values from relative device coordinates to relative plot coordinates";
422
static PyObject * pl_did2pc(PyObject *self, PyObject *args)
424
PLFLT xmin, ymin, xmax, ymax;
425
TRY (PyArg_ParseTuple(args, PL_ARGS("dddd","ffff"),
426
&xmin, &ymin, &xmax, &ymax));
427
pldid2pc(&xmin, &ymin, &xmax, &ymax);
428
return Py_BuildValue(PL_ARGS("(dddd)", "(ffff)"), xmin, ymin, xmax, ymax);
431
static char doc_pldip2dc[]="Converts input values from relative plot coordinates to relative device coordinates";
433
static PyObject * pl_dip2dc(PyObject *self, PyObject *args)
435
PLFLT xmin, ymin, xmax, ymax;
436
TRY (PyArg_ParseTuple(args, PL_ARGS("dddd", "ffff"),
437
&xmin, &ymin, &xmax, &ymax));
438
pldip2dc(&xmin, &ymin, &xmax, &ymax);
439
return Py_BuildValue(PL_ARGS("(dddd)", "(ffff)"), xmin, ymin, xmax, ymax);
442
static char doc_plend[]="End a plotting session for all open streams";
444
static PyObject * pl_end(PyObject *self, PyObject *args)
446
TRY (PyArg_ParseTuple(args, ""));
452
static char doc_plend1[]="End a plotting session for the current stream only";
454
static PyObject * pl_end1(PyObject *self, PyObject *args)
456
TRY (PyArg_ParseTuple(args, ""));
462
static char doc_plenv[]="Simple interface for defining viewport and window";
464
static PyObject * pl_env(PyObject *self, PyObject *args)
466
PLFLT xmin, ymin, xmax, ymax;
468
TRY (PyArg_ParseTuple(args, PL_ARGS("ddddii", "ffffii"),
469
&xmin, &xmax, &ymin, &ymax, &just, &axis));
470
plenv(xmin, xmax, ymin, ymax, just, axis);
475
static char doc_pleop[]="End current page. Should only be used with plbop()";
477
static PyObject * pl_eop(PyObject *self, PyObject *args)
479
TRY (PyArg_ParseTuple(args, ""));
485
static char doc_plerrx[]="Plot horizontal error bars (xmin(i),y(i)) to (xmax(i),y(i))";
487
static PyObject * pl_errx(PyObject *self, PyObject *args)
489
PLINT n, xmaxlen, ylen;
490
PLFLT *xmin, *xmax, *y;
491
PyObject *xminop, *xmaxop, *yop;
492
TRY (PyArg_ParseTuple(args, "OOO", &xminop, &xmaxop, &yop));
493
TRY (pl_PyArray_AsFloatArray(&xminop, &xmin, &n));
494
TRY (pl_PyArray_AsFloatArray(&xmaxop, &xmax, &xmaxlen));
495
TRY (pl_PyArray_AsFloatArray(&yop, &y, &ylen));
496
if (n != xmaxlen || n != ylen) {
497
PyErr_SetString(PyExc_ValueError, "args 1, 2, and 3 should have the same length");
503
plerrx(n, xmin, xmax, y);
511
static char doc_plerry[]="Plot vertical error bars (x,ymin(i)) to (x(i),ymax(i))";
513
static PyObject * pl_erry(PyObject *self, PyObject *args)
515
PLINT n, yminlen, ymaxlen;
516
PLFLT *x, *ymin, *ymax;
517
PyObject *xop, *yminop, *ymaxop;
518
TRY (PyArg_ParseTuple(args, "OOO", &xop, &yminop, &ymaxop));
519
TRY (pl_PyArray_AsFloatArray(&xop, &x, &n));
520
TRY (pl_PyArray_AsFloatArray(&yminop, &ymin, &yminlen));
521
TRY (pl_PyArray_AsFloatArray(&ymaxop, &ymax, &ymaxlen));
522
if (n != yminlen || n != ymaxlen) {
523
PyErr_SetString(PyExc_ValueError, "args 1, 2, and 3 should have the same length");
529
plerry(n, x, ymin, ymax);
537
static char doc_plfamadv[]="Advance to the next family file on the next new page";
539
static PyObject * pl_famadv(PyObject *self, PyObject *args)
541
TRY (PyArg_ParseTuple(args, ""));
547
static char doc_plfill[]="Pattern fills the polygon bounded by the input points";
549
static PyObject * pl_fill(PyObject *self, PyObject *args)
554
TRY (PyArg_ParseTuple(args, "OO", &xop, &yop));
555
TRY (pl_PyArray_AsFloatArray(&xop, &x, &n));
556
TRY (pl_PyArray_AsFloatArray(&yop, &y, &ylen));
558
PyErr_SetString(PyExc_ValueError, "args 1 and 2 should have the same length");
570
static char doc_plflush[]="Flushes the output stream. Use sparingly, if at all.";
572
static PyObject * pl_flush(PyObject *self, PyObject *args)
574
TRY (PyArg_ParseTuple(args, ""));
580
static char doc_plfont[]="Sets the global font flag to 'ifont'";
582
static PyObject * pl_font(PyObject *self, PyObject *args)
585
TRY (PyArg_ParseTuple(args, "i", &ifont));
591
static char doc_plfontld[]="Load specified font set.";
593
static PyObject * pl_fontld(PyObject *self, PyObject *args)
596
TRY (PyArg_ParseTuple(args, "i", &fnt));
602
static char doc_plgchr[]="Get character default height and current (scaled) height";
604
static PyObject * pl_gchr(PyObject *self, PyObject *args)
607
TRY (PyArg_ParseTuple(args, ""));
609
return Py_BuildValue(PL_ARGS("(dd)", "(ff)"), def, ht);
612
static char doc_plgcol0[]="Returns 8 bit RGB values for given color from color map 0";
614
static PyObject * pl_gcol0(PyObject *self, PyObject *args)
616
PLINT icol0, r, b, g;
617
TRY (PyArg_ParseTuple(args, "i", &icol0));
618
plgcol0(icol0, &r, &g, &b);
619
return Py_BuildValue("(iii)", r, g, b);
622
static char doc_plgcolbg[]="Returns the background color by 8 bit RGB value";
624
static PyObject * pl_gcolbg(PyObject *self, PyObject *args)
627
TRY (PyArg_ParseTuple(args, ""));
628
plgcolbg(&r, &g, &b);
629
return Py_BuildValue("(iii)", r, g, b);
632
static char doc_plgdidev[]="Retrieve current window into device space";
634
static PyObject * pl_gdidev(PyObject *self, PyObject *args)
636
PLFLT mar, aspect, jx, jy;
637
TRY (PyArg_ParseTuple(args, ""));
638
plgdidev(&mar, &aspect, &jx, &jy);
639
return Py_BuildValue(PL_ARGS("(dddd)", "(ffff)"), mar, aspect, jx, jy);
642
static char doc_plgdiori[]="Get plot orientation";
644
static PyObject * pl_gdiori(PyObject *self, PyObject *args)
647
TRY (PyArg_ParseTuple(args, ""));
649
return Py_BuildValue(PL_ARGS("d", "f"), rot);
652
static char doc_plgdiplt[]="Retrieve current window into plot space";
654
static PyObject * pl_gdiplt(PyObject *self, PyObject *args)
656
PLFLT xmin, ymin, xmax, ymax;
657
TRY (PyArg_ParseTuple(args, ""));
658
plgdiplt(&xmin, &ymin, &xmax, &ymax);
659
return Py_BuildValue(PL_ARGS("(dddd)", "(ffff)"), xmin, ymin, xmax, ymax);
662
static char doc_plgfam[]="Get family file parameters";
664
static PyObject * pl_gfam(PyObject *self, PyObject *args)
666
PLINT fam, num, bmax;
667
TRY (PyArg_ParseTuple(args, ""));
668
plgfam(&fam, &num, &bmax);
669
return Py_BuildValue("(iii)", fam, num, bmax);
672
static char doc_plgfnam[]="Get the (current) output file name. Must be preallocated to >80 bytes";
674
static PyObject * pl_gfnam(PyObject *self, PyObject *args)
677
TRY (PyArg_ParseTuple(args, ""));
679
return Py_BuildValue("s", fnam);
682
static char doc_plgpage[]="Get output device parameters";
684
static PyObject * pl_gpage(PyObject *self, PyObject *args)
687
PLINT xleng, yleng, xoff, yoff;
688
TRY (PyArg_ParseTuple(args, ""));
689
plgpage(&xp, &yp, &xleng, &yleng, &xoff, &yoff);
690
return Py_BuildValue(PL_ARGS("(ddiiii)", "(ffiiii)"), xp, yp, xleng, yleng, xoff, yoff);
693
static char doc_plgra[]="Switches to graphics screen.";
695
static PyObject * pl_gra(PyObject *self, PyObject *args)
697
TRY (PyArg_ParseTuple(args, ""));
703
static char doc_plgspa[]="Get subpage boundaries in absolute coordinates";
705
static PyObject * pl_gspa(PyObject *self, PyObject *args)
707
PLFLT xmin, xmax, ymin, ymax;
708
TRY (PyArg_ParseTuple(args, ""));
709
plgspa(&xmin, &xmax, &ymin, &ymax);
710
return Py_BuildValue(PL_ARGS("(dddd)", "(ffff)"), xmin, xmax, ymin, ymax);
713
static char doc_plgstrm[]="Get current stream number.";
715
static PyObject * pl_gstrm(PyObject *self, PyObject *args)
718
TRY (PyArg_ParseTuple(args, ""));
720
return Py_BuildValue("i", strm);
723
static char doc_plgver[]="Get the current library version number";
725
static PyObject * pl_gver(PyObject *self, PyObject *args)
728
TRY (PyArg_ParseTuple(args, ""));
730
return Py_BuildValue("s", p_ver);
733
static char doc_plgvpd[]="Get viewport boundaries in normalized device coordinates";
735
static PyObject * pl_gvpd(PyObject *self, PyObject *args)
737
PLFLT xmin, xmax, ymin, ymax;
738
TRY (PyArg_ParseTuple(args, ""));
739
plgvpd(&xmin, &xmax, &ymin, &ymax);
740
return Py_BuildValue(PL_ARGS("(dddd)", "(ffff)"), xmin, xmax, ymin, ymax);
743
static char doc_plgvpw[]="Get viewport boundaries in world coordinates";
745
static PyObject * pl_gvpw(PyObject *self, PyObject *args)
747
PLFLT xmin, xmax, ymin, ymax;
748
TRY (PyArg_ParseTuple(args, ""));
749
plgvpw(&xmin, &xmax, &ymin, &ymax);
750
return Py_BuildValue(PL_ARGS("(dddd)", "(ffff)"), xmin, xmax, ymin, ymax);
753
static char doc_plgxax[]="Get x axis labeling parameters";
755
static PyObject * pl_gxax(PyObject *self, PyObject *args)
757
PLINT digmax, digits;
758
TRY (PyArg_ParseTuple(args, ""));
759
plgxax(&digmax, &digits);
760
return Py_BuildValue("(ii)", digmax, digits);
763
static char doc_plgyax[]="Get y axis labeling parameters";
765
static PyObject * pl_gyax(PyObject *self, PyObject *args)
767
PLINT digmax, digits;
768
TRY (PyArg_ParseTuple(args, ""));
769
plgyax(&digmax, &digits);
770
return Py_BuildValue("(ii)", digmax, digits);
773
static char doc_plgzax[]="Get z axis labeling parameters";
775
static PyObject * pl_gzax(PyObject *self, PyObject *args)
777
PLINT digmax, digits;
778
TRY (PyArg_ParseTuple(args, ""));
779
plgzax(&digmax, &digits);
780
return Py_BuildValue("(ii)", digmax, digits);
783
static char doc_plhist[]="Draws a histogram of n values of a variable in array data[0..n-1]";
785
static PyObject * pl_hist(PyObject *self, PyObject *args)
787
PLINT n, nbin, oldwin;
788
PLFLT *data, datmin, datmax;
790
TRY (PyArg_ParseTuple(args, PL_ARGS("Oddii", "O!ffii"),
791
&op, &datmin, &datmax, &nbin, &oldwin));
792
TRY (pl_PyArray_AsFloatArray(&op, &data, &n));
793
plhist(n, data, datmin, datmax, nbin, oldwin);
799
static char doc_plhls[]="Set current color (map 0) by hue, lightness, and saturation";
801
static PyObject * pl_hls(PyObject *self, PyObject *args)
804
TRY (PyArg_ParseTuple(args, PL_ARGS("ddd", "fff"), &h, &l, &s));
810
static char doc_plinit[]="Initializes PLplot, using preset or default options";
812
static PyObject * pl_init(PyObject *self, PyObject *args)
814
TRY (PyArg_ParseTuple(args, ""));
820
static char doc_pljoin[]="Draws a line segment from (x1, y1) to (x2, y2)";
822
static PyObject * pl_join(PyObject *self, PyObject *args)
824
PLFLT x1, y1, x2, y2;
825
TRY (PyArg_ParseTuple(args, PL_ARGS("dddd", "ffff"), &x1, &y1, &x2, &y2));
826
pljoin(x1, y1, x2, y2);
831
static char doc_pllab[]="Simple routine for labelling graphs";
833
static PyObject * pl_lab(PyObject *self, PyObject *args)
835
const char *xlabel, *ylabel, *tlabel;
836
TRY (PyArg_ParseTuple(args, "sss", &xlabel, &ylabel, &tlabel));
837
pllab(xlabel, ylabel, tlabel);
842
static char doc_pllightsource[]="Sets the 3D position of the light source for use with plotsh3d";
844
static PyObject * pl_lightsource(PyObject *self, PyObject *args)
847
TRY (PyArg_ParseTuple(args, PL_ARGS("ddd", "fff"), &x, &y, &z));
848
pllightsource(x, y, z);
853
static char doc_plline[]="Draws line segments connecting a series of points";
855
static PyObject * pl_line(PyObject *self, PyObject *args)
860
TRY (PyArg_ParseTuple(args, "OO", &xop, &yop));
861
TRY (pl_PyArray_AsFloatArray(&xop, &x, &n));
862
TRY (pl_PyArray_AsFloatArray(&yop, &y, &ylen));
864
PyErr_SetString(PyExc_ValueError, "args 1 and 2 should have the same length");
876
static char doc_plline3[]="Draws a line in 3 space";
878
static PyObject * pl_line3(PyObject *self, PyObject *args)
882
PyObject *xop, *yop, *zop;
883
TRY (PyArg_ParseTuple(args, "OOO", &xop, &yop, &zop));
884
TRY (pl_PyArray_AsFloatArray(&xop, &x, &n));
885
TRY (pl_PyArray_AsFloatArray(&yop, &y, &ylen));
886
TRY (pl_PyArray_AsFloatArray(&zop, &z, &zlen));
887
if (n != ylen || n != zlen) {
888
PyErr_SetString(PyExc_ValueError, "args 1, 2, and 3 should have the same length");
902
static char doc_pllsty[]="Set line style";
904
static PyObject * pl_lsty(PyObject *self, PyObject *args)
907
TRY (PyArg_ParseTuple(args, "i", &lin));
916
static char doc_plmap[]="plot continental outline in world coordinates
918
void plmap(void (*mapform)(PLINT, PLFLT *, PLFLT *), char *type,
919
PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat);
925
static char doc_plmeridians[]="Plot the latitudes and longitudes on the background";
927
void plmeridians(void (*mapform)(PLINT, PLFLT *, PLFLT *),
928
PLFLT dlong, PLFLT dlat,
929
PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat);
932
static char doc_plmesh[]="Plots a mesh representation of the function z[x][y]";
934
static PyObject * pl_mesh(PyObject *self, PyObject *args)
938
PyObject *xop, *yop, *zop;
939
TRY (PyArg_ParseTuple(args, "OOOi", &xop, &yop, &zop, &opt));
940
TRY (pl_PyArray_AsFloatArray(&xop, &x, &nx));
941
TRY (pl_PyArray_AsFloatArray(&yop, &y, &ny));
942
TRY (pl_PyArray_AsFloatMatrix(&zop, &nx, &ny, &z));
943
plmesh(x, y, z, nx, ny, opt);
952
static char doc_plmkstrm[]="Creates a new stream and makes it the default";
954
static PyObject * pl_mkstrm(PyObject *self, PyObject *args)
957
TRY (PyArg_ParseTuple(args, ""));
959
return Py_BuildValue("i", strm);
962
static char doc_plmtex[]="Prints out \"text\" at specified position relative to viewport";
964
static PyObject * pl_mtex(PyObject *self, PyObject *args)
966
const char *side, *text;
967
PLFLT disp, pos, just;
968
TRY (PyArg_ParseTuple(args, PL_ARGS("sddds", "sfffs"),
969
&side, &disp, &pos, &just, &text));
970
plmtex(side, disp, pos, just, text);
975
static char doc_plot3d[]="Plots a 3-d representation of the function z[x][y]";
977
static PyObject * pl_ot3d(PyObject *self, PyObject *args)
980
PLINT nx, ny, opt, side;
981
PyObject *xop, *yop, *zop;
982
TRY (PyArg_ParseTuple(args, "OOOii", &xop, &yop, &zop, &opt, &side));
983
TRY (pl_PyArray_AsFloatArray(&xop, &x, &nx));
984
TRY (pl_PyArray_AsFloatArray(&yop, &y, &ny));
985
TRY (pl_PyArray_AsFloatMatrix(&zop, &nx, &ny, &z));
986
plot3d(x, y, z, nx, ny, opt, side);
995
static char doc_plotsh3d[]="Plot shaded 3-d surface plot";
997
static PyObject * pl_otsh3d(PyObject *self, PyObject *args)
1001
PyObject *xop, *yop, *zop;
1002
TRY (PyArg_ParseTuple(args, "OOOi", &xop, &yop, &zop, &side));
1003
TRY (pl_PyArray_AsFloatArray(&xop, &x, &nx));
1004
TRY (pl_PyArray_AsFloatArray(&yop, &y, &ny));
1005
TRY (pl_PyArray_AsFloatMatrix(&zop, &nx, &ny, &z));
1006
plotsh3d(x, y, z, nx, ny, side);
1015
static char doc_plpat[]="Set fill pattern directly";
1017
static PyObject * pl_pat(PyObject *self, PyObject *args)
1019
PLINT nlin, *inc, *del, dellen;
1020
PyObject *incop, *delop;
1021
TRY (PyArg_ParseTuple(args, "OO", &incop, &delop));
1022
TRY (pl_PyArray_AsIntArray(&incop, &inc, &nlin));
1023
TRY (pl_PyArray_AsIntArray(&delop, &del, &dellen));
1024
if (nlin != dellen) {
1025
PyErr_SetString(PyExc_ValueError, "args 1 and 2 should have the same length");
1030
plpat(nlin, inc, del);
1037
static char doc_plpoin[]="Plots array y against x for n points using ASCII code \"code\"";
1039
static PyObject * pl_poin(PyObject *self, PyObject *args)
1041
PLINT n, code, ylen;
1043
PyObject *xop, *yop;
1044
TRY (PyArg_ParseTuple(args, "OOi", &xop, &yop, &code));
1045
TRY (pl_PyArray_AsFloatArray(&xop, &x, &n));
1046
TRY (pl_PyArray_AsFloatArray(&yop, &y, &ylen));
1048
PyErr_SetString(PyExc_ValueError, "args 1 and 2 should have the same length");
1053
plpoin(n, x, y, code);
1060
static char doc_plpoin3[]="Draws a series of points in 3 space";
1062
static PyObject * pl_poin3(PyObject *self, PyObject *args)
1064
PLINT n, code, ylen, zlen;
1066
PyObject *xop, *yop, *zop;
1067
TRY (PyArg_ParseTuple(args, "OOOi", &xop, &yop, &zop, &code));
1068
TRY (pl_PyArray_AsFloatArray(&xop, &x, &n));
1069
TRY (pl_PyArray_AsFloatArray(&yop, &y, &ylen));
1070
TRY (pl_PyArray_AsFloatArray(&zop, &z, &zlen));
1071
if (n != ylen || n != zlen) {
1072
PyErr_SetString(PyExc_ValueError, "args 1, 2, and 3 should have the same length");
1078
plpoin3(n, x, y, z, code);
1086
static char doc_plpoly3[]="Draws a polygon in 3 space";
1088
static PyObject * pl_poly3(PyObject *self, PyObject *args)
1090
PLINT n, *draw, ylen, zlen, drawlen, ifcc;
1092
PyObject *xop, *yop, *zop, *drawop;
1093
TRY (PyArg_ParseTuple(args, "OOOOi", &xop, &yop, &zop, &drawop, &ifcc));
1094
TRY (pl_PyArray_AsFloatArray(&xop, &x, &n));
1095
TRY (pl_PyArray_AsFloatArray(&yop, &y, &ylen));
1096
TRY (pl_PyArray_AsFloatArray(&zop, &z, &zlen));
1097
TRY (pl_PyArray_AsIntArray(&drawop, &draw, &drawlen));
1098
if (n != ylen || n != zlen) {
1099
PyErr_SetString(PyExc_ValueError, "args 1, 2, and 3 should have the same length");
1106
if (drawlen != n - 1) {
1107
PyErr_SetString(PyExc_ValueError,
1108
"arg 4 should have a length one less than the other args");
1115
plpoly3(n, x, y, z, draw, ifcc);
1123
static char doc_plprec[]="Set the floating point precision (in number of places) in numeric labels";
1125
static PyObject * pl_prec(PyObject *self, PyObject *args)
1128
TRY (PyArg_ParseTuple(args, "ii", &setp, &prec));
1134
static char doc_plpsty[]="Set fill pattern, using one of the predefined patterns";
1136
static PyObject * pl_psty(PyObject *self, PyObject *args)
1139
TRY (PyArg_ParseTuple(args, "i", &patt));
1145
static char doc_plptex[]="Prints out \"text\" at world cooordinate (x,y)";
1147
static PyObject * pl_ptex(PyObject *self, PyObject *args)
1149
PLFLT x, y, dx, dy, just;
1151
TRY (PyArg_ParseTuple(args, PL_ARGS("ddddds", "fffffs"),
1152
&x, &y, &dx, &dy, &just, &text));
1153
plptex(x, y, dx, dy, just, text);
1158
static char doc_plreplot[]="Replays contents of plot buffer to current device/file";
1160
static PyObject * pl_replot(PyObject *self, PyObject *args)
1162
TRY (PyArg_ParseTuple(args, ""));
1168
static char doc_plrgb[]="Set line color by red, green, blue from 0.0=0 to 1.0";
1170
static PyObject * pl_rgb(PyObject *self, PyObject *args)
1173
TRY (PyArg_ParseTuple(args, PL_ARGS("ddd", "fff"), &r, &g, &b));
1179
static char doc_plrgb1[]="Set line color by 8 bit RGB values";
1181
static PyObject * pl_rgb1(PyObject *self, PyObject *args)
1184
TRY (PyArg_ParseTuple(args, "iii", &r, &g, &b));
1190
static char doc_plschr[]="Set character height";
1192
static PyObject * pl_schr(PyObject *self, PyObject *args)
1195
TRY (PyArg_ParseTuple(args, PL_ARGS("dd", "ff"), &def, &scale));
1201
static char doc_plscmap0n[]="Set number of colors in cmap 0";
1203
static PyObject * pl_scmap0n(PyObject *self, PyObject *args)
1206
TRY (PyArg_ParseTuple(args, "i", &ncol0));
1212
static char doc_plscmap1n[]="Set number of colors in cmap 1";
1214
static PyObject * pl_scmap1n(PyObject *self, PyObject *args)
1217
TRY (PyArg_ParseTuple(args, "i", &ncol1));
1223
static char doc_plscmap0[]="Set color map 0 colors by 8 bit RGB values";
1225
static PyObject * pl_scmap0(PyObject *self, PyObject *args)
1228
PLINT ncol0, glen, blen;
1229
PyObject *rop, *gop, *bop;
1230
TRY (PyArg_ParseTuple(args, "OOO", &rop, &gop, &bop));
1231
TRY (pl_PyArray_AsIntArray(&rop, &r, &ncol0));
1232
TRY (pl_PyArray_AsIntArray(&gop, &g, &glen));
1233
TRY (pl_PyArray_AsIntArray(&bop, &b, &blen));
1234
if (ncol0 != glen || ncol0 != blen) {
1235
PyErr_SetString(PyExc_ValueError, "args 1, 2, and 3 should have the same length");
1241
plscmap0(r, g, b, ncol0);
1249
static char doc_plscmap1[]="Set color map 1 colors by 8 bit RGB values";
1251
static PyObject * pl_scmap1(PyObject *self, PyObject *args)
1254
PLINT ncol1, glen, blen;
1255
PyObject *rop, *gop, *bop;
1256
TRY (PyArg_ParseTuple(args, "OOO", &rop, &gop, &bop));
1257
TRY (pl_PyArray_AsIntArray(&rop, &r, &ncol1));
1258
TRY (pl_PyArray_AsIntArray(&gop, &g, &glen));
1259
TRY (pl_PyArray_AsIntArray(&bop, &b, &blen));
1260
if (ncol1 != glen || ncol1 != blen) {
1261
PyErr_SetString(PyExc_ValueError, "args 1, 2, and 3 should have the same length");
1267
plscmap1(r, g, b, ncol1);
1275
static char doc_plscmap1l[]="Set color map 1 colors using a piece-wise linear relationship between intensity [0,1] (cmap 1 index) and position in HLS or RGB color space.";
1277
static PyObject * pl_scmap1l(PyObject *self, PyObject *args)
1279
PLINT itype, npts, coord1len, coord2len, coord3len, revlen;
1280
PLFLT *intensity, *coord1, *coord2, *coord3;
1282
PyObject *intensityop, *coord1op, *coord2op, *coord3op, *revop;
1283
TRY (PyArg_ParseTuple(args, "iOOOOO", &itype, &intensityop,
1284
&coord1op, &coord2op, &coord3op, &revop));
1285
TRY (pl_PyArray_AsFloatArray(&intensityop, &intensity, &npts));
1286
TRY (pl_PyArray_AsFloatArray(&coord1op, &coord1, &coord1len));
1287
TRY (pl_PyArray_AsFloatArray(&coord2op, &coord2, &coord2len));
1288
TRY (pl_PyArray_AsFloatArray(&coord3op, &coord3, &coord3len));
1289
TRY (pl_PyArray_AsIntArray(&revop, &rev, &revlen));
1291
if (npts != coord1len || npts != coord2len || npts != coord3len || npts != revlen) {
1292
PyErr_SetString(PyExc_ValueError, "args 2, 3, 4, 5, and 6 should have the same length");
1293
Py_DECREF(intensityop);
1294
Py_DECREF(coord1op);
1295
Py_DECREF(coord2op);
1296
Py_DECREF(coord3op);
1300
plscmap1l(itype, npts, intensity, coord1, coord2, coord3, rev);
1301
Py_DECREF(intensityop);
1302
Py_DECREF(coord1op);
1303
Py_DECREF(coord2op);
1304
Py_DECREF(coord3op);
1310
static char doc_plscol0[]="Set a given color from color map 0 by 8 bit RGB value";
1312
static PyObject * pl_scol0(PyObject *self, PyObject *args)
1314
PLINT icol0, r, g, b;
1315
TRY (PyArg_ParseTuple(args, "iiii", &icol0, &r, &g, &b));
1316
plscol0(icol0, r, g, b);
1321
static char doc_plscolbg[]="Set the background color by 8 bit RGB value";
1323
static PyObject * pl_scolbg(PyObject *self, PyObject *args)
1326
TRY (PyArg_ParseTuple(args, "iii", &r, &g, &b));
1332
static char doc_plscolor[]="Used to globally turn color output on/off";
1334
static PyObject * pl_scolor(PyObject *self, PyObject *args)
1337
TRY (PyArg_ParseTuple(args, "i", &color));
1343
static char doc_plsdev[]="Set the device (keyword) name";
1345
static PyObject * pl_sdev(PyObject *self, PyObject *args)
1347
const char *devname;
1348
TRY (PyArg_ParseTuple(args, "s", &devname));
1354
static char doc_plsdidev[]="Set window into device space using margin, aspect ratio, and justification";
1356
static PyObject * pl_sdidev(PyObject *self, PyObject *args)
1358
PLFLT mar, aspect, jx, jy;
1359
TRY (PyArg_ParseTuple(args, PL_ARGS("dddd", "ffff"), &mar, &aspect, &jx, &jy));
1360
plsdidev(mar, aspect, jx, jy);
1365
static char doc_plsdimap[]="Set up transformation from metafile coordinates";
1367
static PyObject * pl_sdimap(PyObject *self, PyObject *args)
1369
PLINT dimxmin, dimxmax, dimymin, dimymax, dimxpmm, dimypmm;
1370
TRY (PyArg_ParseTuple(args, PL_ARGS("iiiidd", "iiiiff"),
1371
&dimxmin, &dimxmax, &dimymin,
1372
&dimymax, &dimxpmm, &dimypmm));
1373
plsdimap(dimxmin, dimxmax, dimymin, dimymax, dimxpmm, dimypmm);
1378
static char doc_plsdiori[]="Set plot orientation, specifying rotation in units of pi/2";
1380
static PyObject * pl_sdiori(PyObject *self, PyObject *args)
1383
TRY (PyArg_ParseTuple(args, PL_ARGS("d", "f"), &rot));
1389
static char doc_plsdiplt[]="Set window into plot space";
1391
static PyObject * pl_sdiplt(PyObject *self, PyObject *args)
1393
PLFLT xmin, ymin, xmax, ymax;
1394
TRY (PyArg_ParseTuple(args, PL_ARGS("dddd", "ffff"),
1395
&xmin, &ymin, &xmax, &ymax));
1396
plsdiplt(xmin, ymin, xmax, ymax);
1401
static char doc_plsdiplz[]="Set window into plot space incrementally (zoom)";
1403
static PyObject * pl_sdiplz(PyObject *self, PyObject *args)
1405
PLFLT xmin, ymin, xmax, ymax;
1406
TRY (PyArg_ParseTuple(args, PL_ARGS("dddd", "ffff"),
1407
&xmin, &ymin, &xmax, &ymax));
1408
plsdiplz(xmin, ymin, xmax, ymax);
1413
static char doc_plsesc[]="Set the escape character for text strings";
1415
static PyObject * pl_sesc(PyObject *self, PyObject *args)
1418
TRY (PyArg_ParseTuple(args, "c", &esc));
1424
static char doc_pl_setcontlabelformat[]="Set contour label format";
1426
static PyObject * pl__setcontlabelformat(PyObject *self, PyObject *args)
1429
TRY (PyArg_ParseTuple(args, "ii", &lexp, &sigdig));
1430
pl_setcontlabelformat(lexp, sigdig);
1435
static char doc_pl_setcontlabelparam[]="Set contour label parameters";
1437
static PyObject * pl__setcontlabelparam(PyObject *self, PyObject *args)
1439
PLFLT offset, size, spacing;
1441
TRY (PyArg_ParseTuple(args, PL_ARGS("dddi", "fffi"),
1442
&offset, &size, &spacing, &active));
1443
pl_setcontlabelparam(offset, size, spacing, active);
1448
static char doc_plsfam[]="Set family file parameters";
1450
static PyObject * pl_sfam(PyObject *self, PyObject *args)
1452
PLINT fam, num, bmax;
1453
TRY (PyArg_ParseTuple(args, "iii", &fam, &num, &bmax));
1454
plsfam(fam, num, bmax);
1459
static char doc_plsfnam[]="Set the output file name";
1461
static PyObject * pl_sfnam(PyObject *self, PyObject *args)
1464
TRY (PyArg_ParseTuple(args, "s", &fnam));
1470
#define PyAssert(c,m) if (!(c)) { PyErr_SetString( PyExc_RuntimeError, m ); \
1473
static char doc_plcont[] = "Draws a contour plot from data in z(x,y)";
1478
plcont( z, kx, lx, ky, ly, clev, pltr, xg, yg, wrap )
1479
plcont( z, clev, pltr, xg, yg, wrap )
1481
where in both cases, parameters from pltr to the end are optional.
1483
First case, arg count = 6 +3? +1?
1484
Second case, arg count = 2 +3? +1?
1486
The only way I see to disambiguate this is to either be able to
1487
nondestructively hand parse the arg list, or to mandate fewer valid forms.
1488
Since I cannot find info on how to do a nondestructive trial parse, we opt
1489
for the second. Thus, by fiat, I declare the following forms to be
1492
plcont( z, kx, lx, ky, ly, clev, [pltr, xg, yg, wrap] )
1493
plcont( z, clev, pltr, xg, yg, wrap )
1496
/*static*/ PyObject *pl_cont( PyObject *self, PyObject *args )
1498
PyObject *zop, *xop, *yop;
1499
PLFLT **z, **zwrapped, **zused, *clev;
1501
char *pltrname = NULL;
1502
void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer);
1503
PLPointer pltr_data = NULL;
1509
PLINT kx=0, lx=0, ky=0, ly=0;
1511
int argc = PyTuple_Size( args );
1514
PyAssert( i < argc, "Invalid arg list for plcont" );
1515
zop = PyTuple_GetItem( args, 0 ); i++;
1516
TRY( pl_PyArray_AsFloatMatrix( &zop, &nx, &ny, &z ) );
1518
PyAssert( i < argc, "Invalid arg list for plcont" );
1520
o = PyTuple_GetItem( args, i );
1522
/* printf("printf debug, %d, %d\n", (o)->ob_type, &PyArray_Type);*/
1523
if ( o && PyArray_Check(o) ) {
1524
/* They skipped all the way to clev */
1528
PyAssert( i+3 < argc, "Invalid arg list for plcont" );
1529
/* TRY( PyArg_GetLong( args, argc, i++, &kx ) ); */
1530
kx = PyInt_AsLong( PyTuple_GetItem( args, i++ ) );
1531
/* TRY( PyArg_GetLong( args, argc, i++, &lx ) ); */
1532
lx = PyInt_AsLong( PyTuple_GetItem( args, i++ ) );
1533
/* TRY( PyArg_GetLong( args, argc, i++, &ky ) ); */
1534
ky = PyInt_AsLong( PyTuple_GetItem( args, i++ ) );
1535
/* TRY( PyArg_GetLong( args, argc, i++, &ly ) ); */
1536
ly = PyInt_AsLong( PyTuple_GetItem( args, i++ ) );
1537
o = PyTuple_GetItem( args, i );
1540
/* printf( "plcont, kx=%d lx=%d ky=%d ly=%d\n", kx, lx, ky, ly );*/
1542
/* Must now be positioned on clev, so pull it out and convert. */
1544
TRY( pl_PyArray_AsFloatArray( &o, &clev, &nlev ) );
1546
/* printf( "nlev=%d\n", nlev );*/
1550
/* Now parse the pltr stuff. */
1552
/* printf( "i=%d argc=%d\n", i, argc );*/
1554
/* pltrname = PyArg_GetString( PyTuple_GetItem( args, i++ ) ); */
1555
/* TRY( PyArg_GetString( args, argc, i++, &pltrname ) ); */
1556
pltrname = PyString_AsString( PyTuple_GetItem( args, i++ ) );
1557
/* printf( "pltr=%s\n", pltrname );*/
1559
/* Then there must be at least two args left, which means the xg, yg
1560
stuff has been specified. */
1562
xop = PyTuple_GetItem( args, i++ );
1563
yop = PyTuple_GetItem( args, i++ );
1567
/* TRY( PyArg_GetLong( args, argc, i, &wrap ) ); */
1568
wrap = PyInt_AsLong( PyTuple_GetItem( args, i ) ) ;
1572
/* printf( "wrap=%d\n", wrap ); */
1574
/* Figure out which coordinate transformation model is being used, and setup
1577
if (!pltrname || !strcmp( pltrname, "pltr0")) {
1582
PyErr_SetString( PyExc_RuntimeError,
1583
"Must not specify wrapping with pltr0." );
1587
else if ( !strcmp( pltrname, "pltr1" ) ) {
1589
pltr_data = &cgrid1;
1594
PyErr_SetString( PyExc_RuntimeError,
1595
"Must not specify wrapping with pltr1." );
1599
/* Check dimensionality of xg1 and xg2 */
1600
TRY( pl_PyArray_AsFloatArray( &xop, &cgrid1.xg, &cgrid1.nx ) );
1601
TRY( pl_PyArray_AsFloatArray( &yop, &cgrid1.yg, &cgrid1.ny ) );
1602
if ( (cgrid1.nx != nx) || (cgrid1.ny != ny) ) {
1603
PyErr_SetString( PyExc_RuntimeError,
1604
"Incompatible coord specifiers." );
1608
else if ( !strcmp( pltrname, "pltr2" ) ) {
1609
/* printf( "plcont, setting up for pltr2\n" ); */
1611
/* printf( "plcont, no wrapping is needed.\n" ); */
1612
PLINT xnx, xny, ynx, yny;
1614
TRY( pl_PyArray_AsFloatMatrix( &xop, &xnx, &xny, &xg ) );
1615
TRY( pl_PyArray_AsFloatMatrix( &yop, &ynx, &yny, &yg ) );
1617
if ( (xnx != nx) || (ynx != nx) || (xny != ny) || (yny != ny) ) {
1618
PyErr_SetString( PyExc_RuntimeError,
1619
"Bogus transformation arrays." );
1623
plAlloc2dGrid( &cgrid2.xg, nx, ny );
1624
plAlloc2dGrid( &cgrid2.yg, nx, ny );
1629
for( i=0; i < nx; i++ )
1630
for( j=0; j < ny; j++ ) {
1631
cgrid2.xg[i][j] = xg[i][j];
1632
cgrid2.yg[i][j] = yg[i][j];
1635
else if (wrap == 1) {
1636
PLINT xnx, xny, ynx, yny;
1638
TRY( pl_PyArray_AsFloatMatrix( &xop, &xnx, &xny, &xg ) );
1639
TRY( pl_PyArray_AsFloatMatrix( &yop, &ynx, &yny, &yg ) );
1641
if ( (xnx != nx) || (ynx != nx) || (xny != ny) || (yny != ny) ) {
1642
PyErr_SetString( PyExc_RuntimeError,
1643
"Bogus transformation arrays." );
1647
plAlloc2dGrid( &cgrid2.xg, nx+1, ny );
1648
plAlloc2dGrid( &cgrid2.yg, nx+1, ny );
1649
plAlloc2dGrid( &zwrapped, nx+1, ny );
1654
for( i=0; i < nx; i++ )
1655
for( j=0; j < ny; j++ ) {
1656
cgrid2.xg[i][j] = xg[i][j];
1657
cgrid2.yg[i][j] = yg[i][j];
1658
zwrapped[i][j] = z[i][j];
1661
for( j=0; j < ny; j++ ) {
1662
cgrid2.xg[nx][j] = cgrid2.xg[0][j];
1663
cgrid2.yg[nx][j] = cgrid2.yg[0][j];
1664
zwrapped[nx][j] = zwrapped[0][j];
1669
else if (wrap == 2) {
1670
PLINT xnx, xny, ynx, yny;
1672
TRY( pl_PyArray_AsFloatMatrix( &xop, &xnx, &xny, &xg ) );
1673
TRY( pl_PyArray_AsFloatMatrix( &yop, &ynx, &yny, &yg ) );
1675
if ( (xnx != nx) || (ynx != nx) || (xny != ny) || (yny != ny) ) {
1676
PyErr_SetString( PyExc_RuntimeError,
1677
"Bogus transformation arrays." );
1681
plAlloc2dGrid( &cgrid2.xg, nx, ny+1 );
1682
plAlloc2dGrid( &cgrid2.yg, nx, ny+1 );
1683
plAlloc2dGrid( &zwrapped, nx, ny+1 );
1688
for( i=0; i < nx; i++ )
1689
for( j=0; j < ny; j++ ) {
1690
cgrid2.xg[i][j] = xg[i][j];
1691
cgrid2.yg[i][j] = yg[i][j];
1692
zwrapped[i][j] = z[i][j];
1695
for( i=0; i < nx; i++ ) {
1696
cgrid2.xg[i][ny] = cgrid2.xg[i][0];
1697
cgrid2.yg[i][ny] = cgrid2.yg[i][0];
1698
zwrapped[i][ny] = zwrapped[i][0];
1704
PyErr_SetString( PyExc_RuntimeError,
1705
"Invalid wrap specifier, must be 0, 1 or 2." );
1710
pltr_data = &cgrid2;
1713
PyErr_SetString( PyExc_RuntimeError,
1714
"Unrecognized coordinate transformation spec. Must be pltr0, pltr1 or pltr2." );
1722
/* Now go make the plot. */
1724
plcont( zused, nx, ny, kx, lx, ky, ly, clev, nlev, pltr, pltr_data );
1727
TRY (PyArg_ParseTuple(args, "OiiiiOO!", &op, &kx, &lx, &ky, &ly, &levelop,
1728
&PyFunction_Type, &f));
1729
TRY (pl_PyArray_AsFloatMatrix(&op, &nx, &ny, &z));
1730
TRY (pl_PyArray_AsFloatArray(&levelop, &clevel, &nlevel));
1731
plcont(z, nx, ny, kx, lx, ky, ly, clevel, nlevel, pypltr, f);
1735
if (PyErr_Occurred()) {
1736
PyErr_SetString(PyExc_RuntimeError, "Check your plotter function!");
1740
/* Now free up any space which got allocated for our coordinate trickery. */
1742
if (pltr == pltr1) {
1743
/* Hmm, actually, nothing to do here currently, since we just used the
1744
Python Matrix data directly, rather than allocating private space. */
1746
else if (pltr == pltr2) {
1747
/* printf( "plcont, freeing space for grids used in pltr2\n" ); */
1748
plFree2dGrid( cgrid2.xg, nx, ny );
1749
plFree2dGrid( cgrid2.yg, nx, ny );
1751
plFree2dGrid( zwrapped, nx, ny );
1759
/* AWI: plshades wrapper is modified version of Geoffrey's plshade wrapper.*/
1760
/*--------------------------------------------------------------------------*\
1763
* Processes plshades command.
1765
* data, nx, ny, defined,
1766
* xmin, xmax, ymin, ymax,
1767
* clevel, nlevel, fill_width, cont_color, cont_width,
1768
* plfill, rect, pltr, pltr_data
1770
* We will be getting data through a 2-d Matrix, which carries along
1771
* nx and ny, so no need for those. Toss defined since it's not supported
1772
* anyway. Toss nlevel since clevel carries it along.
1773
* Toss plfill since it is the only valid choice. Take an optional
1774
* pltr spec just as for plcont, and add a wrapping specifier, also just as
1775
* in plcont. So the new command looks like:
1777
* plshades(z, xmin, xmax, ymin, ymax,
1778
* clevel, fill_width, cont_color, cont_width,
1779
* rect, [pltr, x, y,] [wrap])
1780
\*--------------------------------------------------------------------------*/
1782
static char doc_plshades[] = "Color fill plot";
1784
static PyObject *pl_shades( PyObject *self, PyObject *args )
1786
PyObject *zop, *clevelop, *xop=NULL, *yop=NULL;
1787
PLFLT **z, **zwrapped, **zused, *clevel;
1788
PLINT nx, ny, nlevel;
1789
char *pltrname = NULL;
1790
void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer);
1791
PLPointer pltr_data = NULL;
1797
PLFLT xmin, xmax, ymin, ymax;
1798
PLINT fill_width = 0, cont_color = 0, cont_width =0;
1801
TRY( PyArg_ParseTuple( args, PL_ARGS( "OddddOiiii|sOOi",
1802
"OffffOiiii|sOOi" ),
1803
&zop, &xmin, &xmax, &ymin, &ymax,
1804
&clevelop, &fill_width, &cont_color, &cont_width,
1805
&rect, &pltrname, &xop, &yop, &wrap ) );
1807
TRY( pl_PyArray_AsFloatMatrix( &zop, &nx, &ny, &z ) );
1808
TRY( pl_PyArray_AsFloatArray( &clevelop, &clevel, &nlevel ) );
1810
/* Figure out which coordinate transformation model is being used, and setup
1813
if (!pltrname || !strcmp( pltrname, "pltr0")) {
1818
PyErr_SetString( PyExc_RuntimeError,
1819
"Must not specify wrapping with pltr0." );
1823
else if (!strcmp( pltrname, "pltr1" ) ) {
1826
pltr_data = &cgrid1;
1830
PyErr_SetString( PyExc_RuntimeError,
1831
"Must not specify wrapping with pltr1." );
1835
/* Check dimensionality of xg1 and xg2 */
1836
TRY( pl_PyArray_AsFloatArray( &xop, &cgrid1.xg, &cgrid1.nx ) );
1837
TRY( pl_PyArray_AsFloatArray( &yop, &cgrid1.yg, &cgrid1.ny ) );
1838
if ( (cgrid1.nx != nx) || (cgrid1.ny != ny) ) {
1839
PyErr_SetString( PyExc_RuntimeError,
1840
"Incompatible coord specifiers." );
1844
else if ( !strcmp( pltrname, "pltr2" ) ) {
1845
/* printf( "plshades, setting up for pltr2\n" ); */
1847
/* printf( "plshades, no wrapping is needed.\n" ); */
1848
PLINT xnx, xny, ynx, yny;
1850
TRY( pl_PyArray_AsFloatMatrix( &xop, &xnx, &xny, &xg ) );
1851
TRY( pl_PyArray_AsFloatMatrix( &yop, &ynx, &yny, &yg ) );
1853
if ( (xnx != nx) || (ynx != nx) || (xny != ny) || (yny != ny) ) {
1854
PyErr_SetString( PyExc_RuntimeError,
1855
"Bogus transformation arrays." );
1859
plAlloc2dGrid( &cgrid2.xg, nx, ny );
1860
plAlloc2dGrid( &cgrid2.yg, nx, ny );
1865
for( i=0; i < nx; i++ )
1866
for( j=0; j < ny; j++ ) {
1867
cgrid2.xg[i][j] = xg[i][j];
1868
cgrid2.yg[i][j] = yg[i][j];
1871
else if (wrap == 1) {
1872
PLINT xnx, xny, ynx, yny;
1874
TRY( pl_PyArray_AsFloatMatrix( &xop, &xnx, &xny, &xg ) );
1875
TRY( pl_PyArray_AsFloatMatrix( &yop, &ynx, &yny, &yg ) );
1877
if ( (xnx != nx) || (ynx != nx) || (xny != ny) || (yny != ny) ) {
1878
PyErr_SetString( PyExc_RuntimeError,
1879
"Bogus transformation arrays." );
1883
plAlloc2dGrid( &cgrid2.xg, nx+1, ny );
1884
plAlloc2dGrid( &cgrid2.yg, nx+1, ny );
1885
plAlloc2dGrid( &zwrapped, nx+1, ny );
1890
for( i=0; i < nx; i++ )
1891
for( j=0; j < ny; j++ ) {
1892
cgrid2.xg[i][j] = xg[i][j];
1893
cgrid2.yg[i][j] = yg[i][j];
1894
zwrapped[i][j] = z[i][j];
1897
for( j=0; j < ny; j++ ) {
1898
cgrid2.xg[nx][j] = cgrid2.xg[0][j];
1899
cgrid2.yg[nx][j] = cgrid2.yg[0][j];
1900
zwrapped[nx][j] = zwrapped[0][j];
1905
else if (wrap == 2) {
1906
PLINT xnx, xny, ynx, yny;
1908
TRY( pl_PyArray_AsFloatMatrix( &xop, &xnx, &xny, &xg ) );
1909
TRY( pl_PyArray_AsFloatMatrix( &yop, &ynx, &yny, &yg ) );
1911
if ( (xnx != nx) || (ynx != nx) || (xny != ny) || (yny != ny) ) {
1912
PyErr_SetString( PyExc_RuntimeError,
1913
"Bogus transformation arrays." );
1917
plAlloc2dGrid( &cgrid2.xg, nx, ny+1 );
1918
plAlloc2dGrid( &cgrid2.yg, nx, ny+1 );
1919
plAlloc2dGrid( &zwrapped, nx, ny+1 );
1924
for( i=0; i < nx; i++ )
1925
for( j=0; j < ny; j++ ) {
1926
cgrid2.xg[i][j] = xg[i][j];
1927
cgrid2.yg[i][j] = yg[i][j];
1928
zwrapped[i][j] = z[i][j];
1931
for( i=0; i < nx; i++ ) {
1932
cgrid2.xg[i][ny] = cgrid2.xg[i][0];
1933
cgrid2.yg[i][ny] = cgrid2.yg[i][0];
1934
zwrapped[i][ny] = zwrapped[i][0];
1940
PyErr_SetString( PyExc_RuntimeError,
1941
"Invalid wrap specifier, must be 0, 1 or 2." );
1946
pltr_data = &cgrid2;
1949
PyErr_SetString( PyExc_RuntimeError,
1950
"Unrecognized coordinate transformation spec. Must be pltr0, pltr1 or pltr2." );
1954
/* Now go make the plot. */
1956
plshades( zused, nx, ny, NULL, xmin, xmax, ymin, ymax,
1957
clevel, nlevel, fill_width, cont_color, cont_width,
1958
plfill, rect, pltr, pltr_data );
1960
/* Now free up any space which got allocated for our coordinate trickery. */
1962
if (pltr == pltr1) {
1963
/* Hmm, actually, nothing to do here currently, since we just used the
1964
Python Matrix data directly, rather than allocating private space. */
1966
else if (pltr == pltr2) {
1967
/* printf( "plshades, freeing space for grids used in pltr2\n" ); */
1968
plFree2dGrid( cgrid2.xg, nx, ny );
1969
plFree2dGrid( cgrid2.yg, nx, ny );
1971
plFree2dGrid( zwrapped, nx, ny );
1975
Py_INCREF( Py_None );
1979
/* GMF 8/12/96, this implementation cobbled together from tclAPI.c
1980
* with wrap code subsequently fixed by AWI. */
1981
/*--------------------------------------------------------------------------*\
1984
* Processes plshade Tcl command.
1986
* data, nx, ny, defined,
1987
* xmin, xmax, ymin, ymax,
1988
* sh_min, sh_max, sh_cmap, sh_color, sh_width,
1989
* min_col, min_wid, max_col, max_wid,
1990
* plfill, rect, pltr, pltr_data
1992
* We will be getting data through a 2-d Matrix, which carries along
1993
* nx and ny, so no need for those. Toss defined since it's not supported
1994
* anyway. Toss plfill since it is the only valid choice. Take an optional
1995
* pltr spec just as for plcont, and add a wrapping specifier, also just as
1996
* in plcont. So the new command looks like:
1998
* plshade z xmin xmax ymin ymax \
1999
* sh_min sh_max sh_cmap sh_color sh_width \
2000
* min_col min_wid max_col max_wid \
2001
* rect [pltr x y] [wrap]
2002
\*--------------------------------------------------------------------------*/
2004
static char doc_plshade[] = "Color fill plot";
2006
static PyObject *pl_shade( PyObject *self, PyObject *args )
2008
PyObject *zop, *xop=NULL, *yop=NULL;
2010
PLFLT **z, **zwrapped, **zused;
2012
char *pltrname = NULL;
2013
void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer);
2014
PLPointer pltr_data = NULL;
2020
PLFLT xmin, xmax, ymin, ymax, sh_min, sh_max, sh_col;
2021
PLINT sh_cmap =1, sh_wid =2;
2022
PLINT min_col =1, min_wid =0, max_col =0, max_wid =0;
2025
TRY( PyArg_ParseTuple( args, PL_ARGS( "Oddddddidiiiiii|sOOi",
2026
"Offffffifiiiiii|sOOi" ),
2027
&zop, &xmin, &xmax, &ymin, &ymax, &sh_min,
2028
&sh_max, &sh_cmap, &sh_col, &sh_wid,
2029
&min_col, &min_wid, &max_col, &max_wid, &rect,
2030
&pltrname, &xop, &yop, &wrap ) );
2032
TRY( pl_PyArray_AsFloatMatrix( &zop, &nx, &ny, &z ) );
2034
/* Figure out which coordinate transformation model is being used, and setup
2037
if (!pltrname || !strcmp( pltrname, "pltr0")) {
2042
PyErr_SetString( PyExc_RuntimeError,
2043
"Must not specify wrapping with pltr0." );
2047
else if (!strcmp( pltrname, "pltr1" ) ) {
2049
pltr_data = &cgrid1;
2054
PyErr_SetString( PyExc_RuntimeError,
2055
"Must not specify wrapping with pltr1." );
2059
/* Check dimensionality of xg1 and xg2 */
2060
TRY( pl_PyArray_AsFloatArray( &xop, &cgrid1.xg, &cgrid1.nx ) );
2061
TRY( pl_PyArray_AsFloatArray( &yop, &cgrid1.yg, &cgrid1.ny ) );
2062
if ( (cgrid1.nx != nx) || (cgrid1.ny != ny) ) {
2063
PyErr_SetString( PyExc_RuntimeError,
2064
"Incompatible coord specifiers." );
2068
else if ( !strcmp( pltrname, "pltr2" ) ) {
2069
/* printf( "plshade, setting up for pltr2\n" ); */
2071
/* printf( "plshade, no wrapping is needed.\n" ); */
2072
PLINT xnx, xny, ynx, yny;
2074
TRY( pl_PyArray_AsFloatMatrix( &xop, &xnx, &xny, &xg ) );
2075
TRY( pl_PyArray_AsFloatMatrix( &yop, &ynx, &yny, &yg ) );
2077
if ( (xnx != nx) || (ynx != nx) || (xny != ny) || (yny != ny) ) {
2078
PyErr_SetString( PyExc_RuntimeError,
2079
"Bogus transformation arrays." );
2083
plAlloc2dGrid( &cgrid2.xg, nx, ny );
2084
plAlloc2dGrid( &cgrid2.yg, nx, ny );
2089
for( i=0; i < nx; i++ )
2090
for( j=0; j < ny; j++ ) {
2091
cgrid2.xg[i][j] = xg[i][j];
2092
cgrid2.yg[i][j] = yg[i][j];
2095
else if (wrap == 1) {
2096
PLINT xnx, xny, ynx, yny;
2098
TRY( pl_PyArray_AsFloatMatrix( &xop, &xnx, &xny, &xg ) );
2099
TRY( pl_PyArray_AsFloatMatrix( &yop, &ynx, &yny, &yg ) );
2101
if ( (xnx != nx) || (ynx != nx) || (xny != ny) || (yny != ny) ) {
2102
PyErr_SetString( PyExc_RuntimeError,
2103
"Bogus transformation arrays." );
2107
plAlloc2dGrid( &cgrid2.xg, nx+1, ny );
2108
plAlloc2dGrid( &cgrid2.yg, nx+1, ny );
2109
plAlloc2dGrid( &zwrapped, nx+1, ny );
2114
for( i=0; i < nx; i++ )
2115
for( j=0; j < ny; j++ ) {
2116
cgrid2.xg[i][j] = xg[i][j];
2117
cgrid2.yg[i][j] = yg[i][j];
2118
zwrapped[i][j] = z[i][j];
2121
for( j=0; j < ny; j++ ) {
2122
cgrid2.xg[nx][j] = cgrid2.xg[0][j];
2123
cgrid2.yg[nx][j] = cgrid2.yg[0][j];
2124
zwrapped[nx][j] = zwrapped[0][j];
2129
else if (wrap == 2) {
2130
PLINT xnx, xny, ynx, yny;
2132
TRY( pl_PyArray_AsFloatMatrix( &xop, &xnx, &xny, &xg ) );
2133
TRY( pl_PyArray_AsFloatMatrix( &yop, &ynx, &yny, &yg ) );
2135
if ( (xnx != nx) || (ynx != nx) || (xny != ny) || (yny != ny) ) {
2136
PyErr_SetString( PyExc_RuntimeError,
2137
"Bogus transformation arrays." );
2141
plAlloc2dGrid( &cgrid2.xg, nx, ny+1 );
2142
plAlloc2dGrid( &cgrid2.yg, nx, ny+1 );
2143
plAlloc2dGrid( &zwrapped, nx, ny+1 );
2148
for( i=0; i < nx; i++ )
2149
for( j=0; j < ny; j++ ) {
2150
cgrid2.xg[i][j] = xg[i][j];
2151
cgrid2.yg[i][j] = yg[i][j];
2152
zwrapped[i][j] = z[i][j];
2155
for( i=0; i < nx; i++ ) {
2156
cgrid2.xg[i][ny] = cgrid2.xg[i][0];
2157
cgrid2.yg[i][ny] = cgrid2.yg[i][0];
2158
zwrapped[i][ny] = zwrapped[i][0];
2164
PyErr_SetString( PyExc_RuntimeError,
2165
"Invalid wrap specifier, must be 0, 1 or 2." );
2170
pltr_data = &cgrid2;
2173
PyErr_SetString( PyExc_RuntimeError,
2174
"Unrecognized coordinate transformation spec. Must be pltr0, pltr1 or pltr2." );
2182
/* Now go make the plot. */
2184
plfshade( pyf2eval2, &grid, NULL, NULL, nx, ny,
2185
xmin, xmax, ymin, ymax,
2186
sh_min, sh_max, sh_cmap, sh_col, sh_wid,
2187
min_col, min_wid, max_col, max_wid,
2188
plfill, rect, pltr, pltr_data );
2190
/* Now free up any space which got allocated for our coordinate trickery. */
2192
if (pltr == pltr1) {
2193
/* Hmm, actually, nothing to do here currently, since we just used the
2194
Python Matrix data directly, rather than allocating private space. */
2196
else if (pltr == pltr2) {
2197
/* printf( "plshade, freeing space for grids used in pltr2\n" ); */
2198
plFree2dGrid( cgrid2.xg, nx, ny );
2199
plFree2dGrid( cgrid2.yg, nx, ny );
2201
plFree2dGrid( zwrapped, nx, ny );
2205
Py_INCREF( Py_None );
2211
static char doc_plshade[]="Shade region";
2213
void c_plshade(PLFLT **a, PLINT nx, PLINT ny, const char **defined,
2214
PLFLT left, PLFLT right, PLFLT bottom, PLFLT top,
2215
PLFLT shade_min, PLFLT shade_max,
2216
PLINT sh_cmap, PLFLT sh_color, PLINT sh_width,
2217
PLINT min_color, PLINT min_width,
2218
PLINT max_color, PLINT max_width,
2219
void (*fill) (PLINT, PLFLT *, PLFLT *), PLINT rectangular,
2220
void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer),
2221
PLPointer pltr_data);
2223
void plshade1(PLFLT *a, PLINT nx, PLINT ny, const char *defined,
2224
PLFLT left, PLFLT right, PLFLT bottom, PLFLT top,
2225
PLFLT shade_min, PLFLT shade_max,
2226
PLINT sh_cmap, PLFLT sh_color, PLINT sh_width,
2227
PLINT min_color, PLINT min_width,
2228
PLINT max_color, PLINT max_width,
2229
void (*fill) (PLINT, PLFLT *, PLFLT *), PLINT rectangular,
2230
void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer),
2231
PLPointer pltr_data);
2233
void plfshade(PLFLT (*f2eval) (PLINT, PLINT, PLPointer),
2234
PLPointer f2eval_data,
2235
PLFLT (*c2eval) (PLINT, PLINT, PLPointer),
2236
PLPointer c2eval_data,
2238
PLFLT left, PLFLT right, PLFLT bottom, PLFLT top,
2239
PLFLT shade_min, PLFLT shade_max,
2240
PLINT sh_cmap, PLFLT sh_color, PLINT sh_width,
2241
PLINT min_color, PLINT min_width,
2242
PLINT max_color, PLINT max_width,
2243
void (*fill) (PLINT, PLFLT *, PLFLT *), PLINT rectangular,
2244
void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer),
2245
PLPointer pltr_data);
2248
/* I've canned this for now */
2252
c_plslpb(PLFLT lpbxmi, PLFLT lpbxma, PLFLT lpbymi, PLFLT lpbyma);
2255
static char doc_plsmaj[]="Set up lengths of major tick marks";
2257
static PyObject * pl_smaj(PyObject *self, PyObject *args)
2260
TRY (PyArg_ParseTuple(args, PL_ARGS("dd", "ff"), &def, &scale));
2266
static char doc_plsmin[]="Set up lengths of minor tick marks";
2268
static PyObject * pl_smin(PyObject *self, PyObject *args)
2271
TRY (PyArg_ParseTuple(args, PL_ARGS("dd", "ff"), &def, &scale));
2277
static char doc_plsori[]="Set orientation. Must be done before calling plinit.";
2279
static PyObject *pl_sori(PyObject *self, PyObject *args)
2282
TRY (PyArg_ParseTuple(args, "i", &ori));
2288
static char doc_plspage[]="Set output device parameters. Usually ignored by the driver.";
2290
static PyObject * pl_spage(PyObject *self, PyObject *args)
2293
PLINT xleng, yleng, xoff, yoff;
2294
TRY (PyArg_ParseTuple(args, PL_ARGS("ddiiii", "ffiiii"),
2295
&xp, &yp, &xleng, &yleng, &xoff, &yoff));
2296
plspage(xp, yp, xleng, yleng, xoff, yoff);
2301
static char doc_plspause[]="Set the pause (on end-of-page) status";
2303
static PyObject * pl_spause(PyObject *self, PyObject *args)
2306
TRY (PyArg_ParseTuple(args, "i", &pause));
2312
static char doc_plsstrm[]="Set stream number";
2314
static PyObject * pl_sstrm(PyObject *self, PyObject *args)
2317
TRY (PyArg_ParseTuple(args, "i", &strm));
2323
static char doc_plssub[]="Set the number of subwindows in x and y";
2325
static PyObject * pl_ssub(PyObject *self, PyObject *args)
2328
TRY (PyArg_ParseTuple(args, "ii", &nx, &ny));
2334
static char doc_plssym[]="Set symbol height.";
2336
static PyObject * pl_ssym(PyObject *self, PyObject *args)
2339
TRY (PyArg_ParseTuple(args, PL_ARGS("dd", "ff"), &def, &scale));
2345
static char doc_plstar[]="Initialize PLplot, passing in the windows/page settings";
2347
static PyObject * pl_star(PyObject *self, PyObject *args)
2350
TRY (PyArg_ParseTuple(args, "ii", &nx, &ny));
2356
static char doc_plstart[]="Initialize PLplot, passing the device name and windows/page settings";
2358
static PyObject *pl_start(PyObject *self, PyObject *args)
2360
const char *devname;
2362
TRY (PyArg_ParseTuple(args, "sii", &devname, &nx, &ny));
2363
plstart(devname, nx, ny);
2368
static char doc_plstripa[]="Add a point to a stripchart";
2370
static PyObject *pl_stripa(PyObject *self, PyObject *args)
2374
TRY (PyArg_ParseTuple(args, PL_ARGS("iidd", "iiff"), &id, &p, &x, &y));
2375
plstripa(id, p, x, y);
2380
static char doc_plstripc[]="Create a 4-pen stripchart";
2382
static PyObject *pl_stripc(PyObject *self, PyObject *args)
2385
PyObject *collineop, *stylineop, *leglineop;
2387
char *xspec, *yspec;
2388
PLFLT xmin, xmax, xjump, ymin, ymax, xlpos, ylpos;
2389
PLINT y_ascl, acc, colbox, collab;
2390
PLINT *colline, *styline;
2392
char *labx, *laby, *labtop ;
2393
int ncolline, nstyline, nlegline;
2395
TRY (PyArg_ParseTuple(args,
2396
PL_ARGS("ssdddddddiiiiOOOsss", "ssfffffffiiiiOOOsss"),
2398
&xmin, &xmax, &xjump,
2399
&ymin, &ymax, &xlpos, &ylpos,
2400
&y_ascl, &acc, &colbox, &collab,
2401
&collineop, &stylineop, &leglineop,
2402
&labx, &laby, &labtop));
2404
TRY (pl_PyArray_AsIntArray(&collineop, &colline, &ncolline));
2405
TRY (pl_PyArray_AsIntArray(&stylineop, &styline, &nstyline));
2406
TRY (pl_PyList_AsStringArray(leglineop, &legline, &nlegline));
2407
if (ncolline != 4 || nstyline !=4 || nlegline !=4) {
2408
PyErr_SetString( PyExc_RuntimeError,
2409
"colline, nstyline, and nlegline must each have 4 components" );
2410
Py_DECREF(collineop);
2411
Py_DECREF(stylineop);
2412
Py_DECREF(leglineop);
2416
plstripc(&id, xspec, yspec,
2417
xmin, xmax, xjump, ymin, ymax,
2421
colline, styline, legline,
2422
labx, laby, labtop);
2424
Py_DECREF(collineop);
2425
Py_DECREF(stylineop);
2426
Py_DECREF(leglineop);
2427
return Py_BuildValue("i", id);
2430
static char doc_plstripd[]="Deletes and releases memory used by a stripchart";
2432
static PyObject *pl_stripd(PyObject *self, PyObject *args)
2435
TRY (PyArg_ParseTuple(args, "i", &id));
2441
static char doc_plstyl[]="Set up a new line style";
2443
static PyObject * pl_styl(PyObject *self, PyObject *args)
2445
PLINT n, a, b, nms, *mark, *space, spacelen;
2446
PyObject *markop, *spaceop;
2447
if (PyArg_ParseTuple(args, "iii", &n, &a, &b))
2451
TRY (PyArg_ParseTuple(args, "OO", &markop, &spaceop));
2452
TRY (pl_PyArray_AsIntArray(&markop, &mark, &nms));
2453
TRY (pl_PyArray_AsIntArray(&spaceop, &space, &spacelen));
2454
if (nms != spacelen) {
2455
PyErr_SetString(PyExc_ValueError, "args 1 and 2 should have the same length");
2460
plstyl(nms, mark, space);
2468
static char doc_plsvpa[]="Sets the edges of the viewport to the specified absolute coordinates";
2470
static PyObject * pl_svpa(PyObject *self, PyObject *args)
2472
PLFLT xmin, xmax, ymin, ymax;
2473
TRY (PyArg_ParseTuple(args, PL_ARGS("dddd", "ffff"),
2474
&xmin, &xmax, &ymin, &ymax));
2475
plsvpa(xmin, xmax, ymin, ymax);
2480
static char doc_plsxax[]="Set x axis labeling parameters";
2482
static PyObject * pl_sxax(PyObject *self, PyObject *args)
2484
PLINT digmax, digits;
2485
TRY (PyArg_ParseTuple(args, "ii", &digmax, &digits));
2486
plsxax(digmax, digits);
2491
static char doc_plsxwin[]="Set inferior X window";
2493
static PyObject * pl_sxwin(PyObject *self, PyObject *args)
2496
TRY (PyArg_ParseTuple(args, "i", &window_id));
2502
static char doc_plsyax[]="Set y axis labeling parameters";
2504
static PyObject * pl_syax(PyObject *self, PyObject *args)
2506
PLINT digmax, digits;
2507
TRY (PyArg_ParseTuple(args, "ii", &digmax, &digits));
2508
plsyax(digmax, digits);
2513
static char doc_plsym[]="Plots array y against x for n points using Hershey symbol \"code\"";
2515
static PyObject * pl_sym(PyObject *self, PyObject *args)
2517
PLINT n, code, ylen;
2519
PyObject *xop, *yop;
2520
TRY (PyArg_ParseTuple(args, "OOi", &xop, &yop, &code));
2521
TRY (pl_PyArray_AsFloatArray(&xop, &x, &n));
2522
TRY (pl_PyArray_AsFloatArray(&yop, &y, &ylen));
2524
PyErr_SetString(PyExc_ValueError, "args 1 and 2 should have the same length");
2529
plsym(n, x, y, code);
2536
static char doc_plszax[]="Set z axis labeling parameters";
2538
static PyObject * pl_szax(PyObject *self, PyObject *args)
2540
PLINT digmax, digits;
2541
TRY (PyArg_ParseTuple(args, "ii", &digmax, &digits));
2542
plszax(digmax, digits);
2547
static char doc_pltext[]="Switches to text screen";
2549
static PyObject * pl_text(PyObject *self, PyObject *args)
2551
TRY (PyArg_ParseTuple(args, ""));
2557
static char doc_plvasp[]="Sets the edges of the viewport with the given aspect ratio, leaving room for labels";
2559
static PyObject * pl_vasp(PyObject *self, PyObject *args)
2562
TRY (PyArg_ParseTuple(args, PL_ARGS("d", "f"), &aspect));
2568
static char doc_plvpas[]="Creates the largest viewport of the specified aspect ratio that fits within the specified normalized subpage coordinates";
2570
static PyObject * pl_vpas(PyObject *self, PyObject *args)
2572
PLFLT xmin, xmax, ymin, ymax, aspect;
2573
TRY (PyArg_ParseTuple(args, PL_ARGS("ddddd", "fffff"),
2574
&xmin, &xmax, &ymin, &ymax, &aspect));
2575
plvpas(xmin, xmax, ymin, ymax, aspect);
2580
static char doc_plvpor[]="Creates a viewport with the specified normalized subpage coordinates";
2582
static PyObject * pl_vpor(PyObject *self, PyObject *args)
2584
PLFLT xmin, xmax, ymin, ymax;
2585
TRY (PyArg_ParseTuple(args, PL_ARGS("dddd", "ffff"),
2586
&xmin, &xmax, &ymin, &ymax));
2587
plvpor(xmin, xmax, ymin, ymax);
2592
static char doc_plvsta[]="Defines a \"standard\" viewport with seven character heights for the left margin and four character heights everywhere else";
2594
static PyObject * pl_vsta(PyObject *self, PyObject *args)
2596
TRY (PyArg_ParseTuple(args, ""));
2602
static char doc_plw3d[]="Set up a window for three-dimensional plotting";
2604
static PyObject * pl_w3d(PyObject *self, PyObject *args)
2606
PLFLT basex, basey, height, xmin0, xmax0, ymin0, ymax0, zmin0, zmax0, alt, az;
2607
TRY (PyArg_ParseTuple(args, PL_ARGS("ddddddddddd", "fffffffffff"),
2608
&basex, &basey, &height, &xmin0, &xmax0, &ymin0, &ymax0,
2609
&zmin0, &zmax0, &alt, &az));
2610
plw3d(basex, basey, height, xmin0, xmax0, ymin0, ymax0, zmin0, zmax0, alt, az);
2615
static char doc_plwid[]="Set pen width";
2617
static PyObject * pl_wid(PyObject *self, PyObject *args)
2620
TRY (PyArg_ParseTuple(args, "i", &width));
2626
static char doc_plwind[]="Set up world coordinates of the viewport boundaries (2d plots)";
2628
static PyObject * pl_wind(PyObject *self, PyObject *args)
2630
PLFLT xmin, xmax, ymin, ymax;
2631
TRY (PyArg_ParseTuple(args, PL_ARGS("dddd", "ffff"),
2632
&xmin, &xmax, &ymin, &ymax));
2633
plwind(xmin, xmax, ymin, ymax);
2638
static char doc_plParseOpts[]="Process PLplot internal options list";
2640
static PyObject * pl_ParseOpts(PyObject *self, PyObject *args)
2646
TRY (PyArg_ParseTuple(args, "O!i", &PyList_Type, &argvlist, &mode));
2647
TRY (pl_PyList_AsStringArray(argvlist, &argv, &argc));
2648
status = plParseOpts(&argc, argv, mode);
2649
TRY (pl_PyList_SetFromStringArray(argvlist, argv, argc));
2651
return Py_BuildValue("i", status);
2657
static char doc_plParseOpts[]="Process options list
2659
int plParseOpts(int *p_argc, char **argv, PLINT mode, PLOptionTable *option_table,
2660
void (*usage_handler) (char *));
2663
static char doc_plsetopt[]="Process input strings, treating them as an option and argument pair";
2665
static PyObject * pl_setopt(PyObject *self, PyObject *args)
2669
TRY (PyArg_ParseTuple(args, "ss", &opt, &optarg));
2670
status = plsetopt(opt, optarg);
2671
return Py_BuildValue("i", status);
2674
static char doc_plGetCursor[]="Wait for right button mouse event and translate to world coordinates";
2676
static PyObject * pl_GetCursor(PyObject *self, PyObject *args)
2681
TRY (PyArg_ParseTuple(args, ""));
2682
translated = plGetCursor(&gin);
2684
result = Py_BuildValue(PL_ARGS("(dddd)", "(ffff)"), gin.dX, gin.dY, gin.wX, gin.wY);
2686
result = Py_BuildValue(PL_ARGS("(dd)", "(ff)"), gin.dX, gin.dY);
2691
static char doc_xormod[]="enter/leave xor mode";
2693
static PyObject * pl_xormod(PyObject *self, PyObject *args)
2696
TRY (PyArg_ParseTuple(args, "i", &mode));
2697
plxormod(mode, &st);
2698
return Py_BuildValue("i", st);
2702
static PyMethodDef pl_methods[] = {
2703
{"pladv", pl_adv, METH_VARARGS, doc_pladv},
2704
{"plarrows", pl_arrows, METH_VARARGS, doc_plarrows},
2705
{"plaxes", pl_axes, METH_VARARGS, doc_plaxes},
2706
{"plbin", pl_bin, METH_VARARGS, doc_plbin},
2707
{"plbop", pl_bop, METH_VARARGS, doc_plbop},
2708
{"plbox", pl_box, METH_VARARGS, doc_plbox},
2709
{"plbox3", pl_box3, METH_VARARGS, doc_plbox3},
2710
{"plcalc_world", pl_calc_world, METH_VARARGS, doc_plcalc_world},
2711
{"plclr", pl_eop, METH_VARARGS, doc_pleop}, /* old name for backward compatibility */
2712
{"plcol", pl_col0, METH_VARARGS, doc_plcol0}, /* old name for backward compatibility */
2713
{"plcol0", pl_col0, METH_VARARGS, doc_plcol0},
2714
{"plcol1", pl_col1, METH_VARARGS, doc_plcol1},
2715
{"plcont", pl_cont, METH_VARARGS, doc_plcont},
2716
{"plcont2", pl_cont2, METH_VARARGS, doc_plcont2},
2717
{"plcpstrm", pl_cpstrm, METH_VARARGS, doc_plcpstrm},
2718
{"pldid2pc", pl_did2pc, METH_VARARGS, doc_pldid2pc},
2719
{"pldip2dc", pl_dip2dc, METH_VARARGS, doc_pldip2dc},
2720
{"plend", pl_end, METH_VARARGS, doc_plend},
2721
{"plend1", pl_end1, METH_VARARGS, doc_plend1},
2722
{"plenv", pl_env, METH_VARARGS, doc_plenv},
2723
{"pleop", pl_eop, METH_VARARGS, doc_pleop},
2724
{"plerrx", pl_errx, METH_VARARGS, doc_plerrx},
2725
{"plerry", pl_erry, METH_VARARGS, doc_plerry},
2726
{"plfamadv", pl_famadv, METH_VARARGS, doc_plfamadv},
2727
{"plfill", pl_fill, METH_VARARGS, doc_plfill},
2728
{"plflush", pl_flush, METH_VARARGS, doc_plflush},
2729
{"plfont", pl_font, METH_VARARGS, doc_plfont},
2730
{"plfontld", pl_fontld, METH_VARARGS, doc_plfontld},
2731
{"plgchr", pl_gchr, METH_VARARGS, doc_plgchr},
2732
{"plgcol0", pl_gcol0, METH_VARARGS, doc_plgcol0},
2733
{"plgcolbg", pl_gcolbg, METH_VARARGS, doc_plgcolbg},
2734
{"plgdidev", pl_gdidev, METH_VARARGS, doc_plgdidev},
2735
{"plgdiori", pl_gdiori, METH_VARARGS, doc_plgdiori},
2736
{"plgdiplt", pl_gdiplt, METH_VARARGS, doc_plgdiplt},
2737
{"plgfam", pl_gfam, METH_VARARGS, doc_plgfam},
2738
{"plgfnam", pl_gfnam, METH_VARARGS, doc_plgfnam},
2739
{"plgpage", pl_gpage, METH_VARARGS, doc_plgpage},
2740
{"plgra", pl_gra, METH_VARARGS, doc_plgra},
2741
{"plgspa", pl_gspa, METH_VARARGS, doc_plgspa},
2742
{"plgstrm", pl_gstrm, METH_VARARGS, doc_plgstrm},
2743
{"plgver", pl_gver, METH_VARARGS, doc_plgver},
2744
{"plgvpd", pl_gvpd, METH_VARARGS, doc_plgvpd},
2745
{"plgvpw", pl_gvpw, METH_VARARGS, doc_plgvpw},
2746
{"plPgvpw", pl_gvpw, METH_VARARGS, doc_plgvpw}, /* old name */
2747
{"plgxax", pl_gxax, METH_VARARGS, doc_plgxax},
2748
{"plgyax", pl_gyax, METH_VARARGS, doc_plgyax},
2749
{"plgzax", pl_gzax, METH_VARARGS, doc_plgzax},
2750
{"plhist", pl_hist, METH_VARARGS, doc_plhist},
2751
{"plhls", pl_hls, METH_VARARGS, doc_plhls},
2752
{"plinit", pl_init, METH_VARARGS, doc_plinit},
2753
{"pljoin", pl_join, METH_VARARGS, doc_pljoin},
2754
{"pllab", pl_lab, METH_VARARGS, doc_pllab},
2755
{"pllightsource", pl_lightsource, METH_VARARGS, doc_pllightsource},
2756
{"plline", pl_line, METH_VARARGS, doc_plline},
2757
{"plline3", pl_line3, METH_VARARGS, doc_plline3},
2758
{"pllsty", pl_lsty, METH_VARARGS, doc_pllsty},
2759
{"plmesh", pl_mesh, METH_VARARGS, doc_plmesh},
2760
{"plmkstrm", pl_mkstrm, METH_VARARGS, doc_plmkstrm},
2761
{"plmtex", pl_mtex, METH_VARARGS, doc_plmtex},
2762
{"plot3d", pl_ot3d, METH_VARARGS, doc_plot3d},
2763
{"plotsh3d", pl_otsh3d, METH_VARARGS, doc_plotsh3d},
2764
{"plpage", pl_bop, METH_VARARGS, doc_plbop}, /* old name for backward compatibility */
2765
{"plpat", pl_pat, METH_VARARGS, doc_plpat},
2766
{"plpoin", pl_poin, METH_VARARGS, doc_plpoin},
2767
{"plpoin3", pl_poin3, METH_VARARGS, doc_plpoin3},
2768
{"plpoly3", pl_poly3, METH_VARARGS, doc_plpoly3},
2769
{"plprec", pl_prec, METH_VARARGS, doc_plprec},
2770
{"plpsty", pl_psty, METH_VARARGS, doc_plpsty},
2771
{"plptex", pl_ptex, METH_VARARGS, doc_plptex},
2772
{"plreplot", pl_replot, METH_VARARGS, doc_plreplot},
2773
{"plrgb", pl_rgb, METH_VARARGS, doc_plrgb},
2774
{"plrgb1", pl_rgb1, METH_VARARGS, doc_plrgb1},
2775
{"plschr", pl_schr, METH_VARARGS, doc_plschr},
2776
{"plscmap0n", pl_scmap0n, METH_VARARGS, doc_plscmap0n},
2777
{"plscmap1n", pl_scmap1n, METH_VARARGS, doc_plscmap1n},
2778
{"plscmap0", pl_scmap0, METH_VARARGS, doc_plscmap0},
2779
{"plscmap1", pl_scmap1, METH_VARARGS, doc_plscmap1},
2780
{"plscmap1l", pl_scmap1l, METH_VARARGS, doc_plscmap1l},
2781
{"plscol0", pl_scol0, METH_VARARGS, doc_plscol0},
2782
{"plscolbg", pl_scolbg, METH_VARARGS, doc_plscolbg},
2783
{"plscolor", pl_scolor, METH_VARARGS, doc_plscolor},
2784
{"plsdev", pl_sdev, METH_VARARGS, doc_plsdev},
2785
{"plsdidev", pl_sdidev, METH_VARARGS, doc_plsdidev},
2786
{"plsdimap", pl_sdimap, METH_VARARGS, doc_plsdimap},
2787
{"plsdiori", pl_sdiori, METH_VARARGS, doc_plsdiori},
2788
{"plsdiplt", pl_sdiplt, METH_VARARGS, doc_plsdiplt},
2789
{"plsdiplz", pl_sdiplz, METH_VARARGS, doc_plsdiplz},
2790
{"plsesc", pl_sesc, METH_VARARGS, doc_plsesc},
2791
{"pl_setcontlabelformat", pl__setcontlabelformat, METH_VARARGS, doc_pl_setcontlabelformat},
2792
{"pl_setcontlabelparam", pl__setcontlabelparam, METH_VARARGS, doc_pl_setcontlabelparam},
2793
{"plsfam", pl_sfam, METH_VARARGS, doc_plsfam},
2794
{"plsfnam", pl_sfnam, METH_VARARGS, doc_plsfnam},
2795
{"plshades", pl_shades, METH_VARARGS, doc_plshades},
2796
{"plshade", pl_shade, METH_VARARGS, doc_plshade},
2797
{"plsmaj", pl_smaj, METH_VARARGS, doc_plsmaj},
2798
{"plsmin", pl_smin, METH_VARARGS, doc_plsmin},
2799
{"plsori", pl_sori, METH_VARARGS, doc_plsori},
2800
{"plspage", pl_spage, METH_VARARGS, doc_plspage},
2801
{"plspause", pl_spause, METH_VARARGS, doc_plspause},
2802
{"plsstrm", pl_sstrm, METH_VARARGS, doc_plsstrm},
2803
{"plssub", pl_ssub, METH_VARARGS, doc_plssub},
2804
{"plssym", pl_ssym, METH_VARARGS, doc_plssym},
2805
{"plstar", pl_star, METH_VARARGS, doc_plstar},
2806
{"plstart", pl_start, METH_VARARGS, doc_plstart},
2807
{"plstripa", pl_stripa, METH_VARARGS, doc_plstripa},
2808
{"plstripc", pl_stripc, METH_VARARGS, doc_plstripc},
2809
{"plstripd", pl_stripd, METH_VARARGS, doc_plstripd},
2810
{"plstyl", pl_styl, METH_VARARGS, doc_plstyl},
2811
{"plsvpa", pl_svpa, METH_VARARGS, doc_plsvpa},
2812
{"plsxax", pl_sxax, METH_VARARGS, doc_plsxax},
2813
{"plsxwin", pl_sxwin, METH_VARARGS, doc_plsxwin},
2814
{"plsyax", pl_syax, METH_VARARGS, doc_plsyax},
2815
{"plsym", pl_sym, METH_VARARGS, doc_plsym},
2816
{"plszax", pl_szax, METH_VARARGS, doc_plszax},
2817
{"pltext", pl_text, METH_VARARGS, doc_pltext},
2818
{"plvasp", pl_vasp, METH_VARARGS, doc_plvasp},
2819
{"plvpas", pl_vpas, METH_VARARGS, doc_plvpas},
2820
{"plvpor", pl_vpor, METH_VARARGS, doc_plvpor},
2821
{"plvsta", pl_vsta, METH_VARARGS, doc_plvsta},
2822
{"plw3d", pl_w3d, METH_VARARGS, doc_plw3d},
2823
{"plwid", pl_wid, METH_VARARGS, doc_plwid},
2824
{"plwind", pl_wind, METH_VARARGS, doc_plwind},
2825
{"plxormod", pl_xormod, METH_VARARGS, doc_xormod},
2826
{"plParseOpts", pl_ParseOpts, METH_VARARGS, doc_plParseOpts},
2827
{"plsetopt", pl_setopt, METH_VARARGS, doc_plsetopt},
2828
{"plGetCursor", pl_GetCursor, METH_VARARGS, doc_plGetCursor},
2829
{NULL, NULL, 0, NULL}
2840
/* Create the module and add the functions */
2841
m = Py_InitModule("pl", pl_methods);
2842
d = PyModule_GetDict(m);
2844
/* Add some symbolic constants to the module */
2845
v = PyInt_FromLong(PL_PARSE_PARTIAL);
2846
PyDict_SetItemString(d, "PL_PARSE_PARTIAL", v);
2849
v = PyInt_FromLong(PL_PARSE_FULL);
2850
PyDict_SetItemString(d, "PL_PARSE_FULL", v);
2853
v = PyInt_FromLong(PL_PARSE_QUIET);
2854
PyDict_SetItemString(d, "PL_PARSE_QUIET", v);
2857
v = PyInt_FromLong(PL_PARSE_NODELETE);
2858
PyDict_SetItemString(d, "PL_PARSE_NODELETE", v);
2861
v = PyInt_FromLong(PL_PARSE_SHOWALL);
2862
PyDict_SetItemString(d, "PL_PARSE_SHOWALL", v);
2865
v = PyInt_FromLong(PL_PARSE_OVERRIDE);
2866
PyDict_SetItemString(d, "PL_PARSE_OVERRIDE", v);
2869
v = PyInt_FromLong(PL_PARSE_NOPROGRAM);
2870
PyDict_SetItemString(d, "PL_PARSE_NOPROGRAM", v);
2873
v = PyInt_FromLong(PL_PARSE_NODASH);
2874
PyDict_SetItemString(d, "PL_PARSE_NODASH", v);
2877
/* Check for errors */
2878
if (PyErr_Occurred())
2879
Py_FatalError("pl module initialization failed");