forked from Fellypao/scidavis-handbook
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sec-python.html
2180 lines (2176 loc) · 113 KB
/
sec-python.html
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Python</title>
<link rel="stylesheet" type="text/css" href="scidavis.css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<meta name="keywords" content="Qt, SciDAVis, Data, Analysis, Plotting">
<link rel="home" href="index.html" title="The SciDAVis Handbook">
<link rel="up" href="scripting.html" title="Chapter 4. Scripting">
<link rel="prev" href="scripting.html" title="Chapter 4. Scripting">
<link rel="next" href="reference.html" title="Chapter 5. Command Reference">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Python</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="scripting.html">Prev</a> </td>
<th width="60%" align="center">Chapter 4. Scripting</th>
<td width="20%" align="right"> <a accesskey="n" href="reference.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-python"></a>Python</h2></div></div></div>
<a class="indexterm" name="idp1396139684"></a><p>This module provides bindings to the <a class="ulink" href="https://www.python.org" target="_top">Python</a> programming language. Basic
usage in the context of SciDAVis will be discussed below, but for more
in-depth information on the language itself, please refer to its excellent
<a class="ulink" href="https://www.python.org/doc" target="_top">documentation</a>.</p>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idp1396141244"></a>Getting Started</h3></div></div></div>
<p>Make sure your current project uses Python as its interpreter by
selecting the menu point Scripting->Scripting Language and
double-clicking on "Python" in the resulting dialog (if the dialog
appears, but does not contain the "Python" item, your installation
of SciDAVis has been compiled without Python support).
Next, open a Notes window and enter
<strong class="userinput"><code>print "Hello World!"</code></strong>. Position the cursor
anywhere on this line and press Ctrl+J, or select "Execute" from
the context menu. The string "Hello World!" should appear below the
line you entered. Congratulations, you've made contact with Python!
You can also enter more complex code fragments, such as function or
class definitions, in which case you have to select the whole code
block before executing it.</p>
<p>You can also use Notes windows as a handy calculator. Enter a
mathematical expression on a line of its own - say,
<strong class="userinput"><code>5*sin(pi/2)</code></strong>. Press Ctr+Enter, or select
"Evaluate" from the context menu. You are rewarded by a new line,
stating (to general astonishment), that the result of evaluating
your expression is <code class="computeroutput">#> 5</code>. If
you have <a class="ulink" href="https://www.scipy.org" target="_top">SciPy</a> and/or
<a class="ulink" href="http://pygsl.sourceforge.net" target="_top">PyGSL</a> installed, you
will have immediate access to a huge number of interesting
functions, browseable via the sub-menu "Functions" of the context
menu. Pressing Shift+F1 while in this menu will give you a short
description of the current function. The advantage of only
executing/evaluating single lines or selections on request is that
you can freely mix text and calculations within a Notes window.</p>
<p>Another particularly handy place for using Python code are
column formulas. These work just like evaluating expressions
in Note windows, with the additional advantage of some pre-defined
variables: i (the row currently being computed), j (the column
number), sr (start row), er (end row) and self (the table to which the
column being computed belongs; see below for what you can do with it).
</p>
<p>If you are already familiar with Python, you might ask yourself at
this point if you can use more complicated column formulas than just
single expressions (for instance, if:/else: decisions based on the
current row number). The answer is: yes, you can. For the benefit of
those not familiar with Python, we will give a short introduction to
the language before discussing how to do this.</p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idp1396146604"></a>Python Basics</h3></div></div></div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idp1396146972"></a>Expressions</h4></div></div></div>
<p>Mathematical expressions work largely as expected. However,
there's one caveat, especially when switching from muParser:
<strong class="userinput"><code>a^b</code></strong> does not mean "raise a to the power of b" but
rather "bitwise exclusive or of a and b"; Python's power operator is **.
Thus: </p>
<pre class="screen" width="40">
<strong class="userinput"><code>2^3 # read: 10 xor 11 = 01</code></strong>
<code class="computeroutput">#> 1</code>
<strong class="userinput"><code>2**3</code></strong>
<code class="computeroutput">#> 8</code>
</pre>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idp1396150076"></a>Statements</h4></div></div></div>
<p>One thing you have to know when working with Python is that
indentation is very important. It is used for grouping (most other
languages use either braces or keywords like
<strong class="userinput"><code>do...end</code></strong> for this). For example, executing the
following: </p>
<pre class="programlisting" width="40">
x=23
for i in (1,4,5):
x=i**2
print(x)
</pre>
<p> will do what you would expect: it prints out the numbers 1, 16 and
25; each on a line of its own. Deleting just a bit of space will change
the functionality of your program: </p>
<pre class="programlisting" width="40">
x=23
for i in (1,4,5):
x=i**2
print(x)
</pre>
<p> will print out only one number - no, not 23, but rather 25. This
example was designed to also teach you something about variable scoping:
There are no block-local variables in Python.</p>
<p>There are two different variable scopes to be aware of: local and
global variables. Unless specified otherwise, variables are local to the
context in which they were defined. Thus, the variable
<code class="varname">x</code> can have three different values in, say, two
different Note windows and a column formula. Global variables on the
other hand can be accessed from everywhere within your project. A
variable <code class="varname">x</code> is declared global by executing the
statement <strong class="userinput"><code>global x</code></strong>. You have to do this before
assigning a value to <code class="varname">x</code>, but you have to do it only
once within the project (no need to "import" the variable before using
it). Note that there is a slight twist to these rules when you
define your own functions.</p>
<p>The basic syntax for defining a function (for use within one
particular note, for example) is </p>
<pre class="programlisting" width="40">
def answer():
return 42
</pre>
<p> If you want your function to be accessible from the rest of your
project, you have to declare it global before the definition: </p>
<pre class="programlisting" width="40">
global answer
def answer():
return 42
</pre>
<p> You can add your own function to SciDAVis's function list. We'll
also provide a documentation string that will show up, for example, in
the "set column values" dialog: </p>
<pre class="programlisting" width="40">
global answer
def answer():
"Return the answer to the ultimate question about life, the universe and everything."
return 42
sci.mathFunctions["answer"] = answer
</pre>
<p> If you want to remove a function from the list,
execute </p>
<pre class="programlisting" width="40">
del sci.mathFunctions["answer"]
</pre>
<p>Note that functions have their own local scope. That means that if
you enter a function definition in a Notes window, you will not be able to
access (neither reading nor writing) Notes-local variables from within
the function. However, you can access global variables as usual.</p>
<p>If-then-else decisions are entered as follows: </p>
<pre class="programlisting" width="40">
if x>23:
print(x)
else:
print("The value is too small.")
</pre>
<p>You can do loops, too: </p>
<pre class="programlisting" width="40">
for i in range(1, 11):
print(i)
</pre>
<p> This will print out the numbers between 1 and 10 inclusively (the
upper limit does not belong to the range, while the lower limit
does).</p>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idp1396159516"></a>Hints on Python 2 vs Python 3 usage</h4></div></div></div>
<p>In version 1.23 of SciDAVis it was added Python 3 support for scripting. Then, in addition to the differences between Python version 2 and 3 <a class="ulink" href="https://docs.python.org/3.0/whatsnew/3.0.html" target="_top">listed here</a>, there are some small tips for users that use non-ASCII characters in python scripts.</p>
<p>When SciDAVis is built against Python 3, it is required to specify the character encoding in the scripting note (at the beginning, preferably) using: </p>
<pre class="programlisting" width="40">
# coding=<encoding name> </pre>
<p> E. g.: to use the UTF-8 character encoding, add </p>
<pre class="programlisting" width="40">
# coding=utf8 </pre>
<p> to the note.</p>
<p>When SciDAVis is built against Python 2, it is required to specify the character encoding <span class="emphasis"><em>each time</em></span> you use a non-ASCII character inside a command in the following way: </p>
<pre class="programlisting" width="40">
command(unicode("<string to be used>","utf8")) </pre>
<p> Some examples are:</p>
<p>- To use the print statement:</p>
<pre class="programlisting" width="40">
print(unicode("<string to be used>","utf8")) </pre>
<p>
- To modify X axis title on a graph:</p>
<pre class="programlisting" width="40">
g = graph("Graph1")
l = g.activeLayer()
l.setXTitle(unicode("<desired X title>","utf8"))</pre>
<p>
- To access a graph whose window name has a non-ASCII character:</p>
<pre class="programlisting" width="40">
g = graph(unicode("<literal window name>","utf8")) </pre>
</div>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="idp1396165756"></a>Evaluation Reloaded</h3></div></div></div>
<p>As we've already mentioned above, there's a bit more to evaluation
than just expressions. Note that Python itself can indeed only
evaluate expressions; the following describes a feature of SciDAVis
added on top of Python in order to support more interesting column
formulas.</p>
<p>If you use statements (e.g. variable assignments or control
structures) in a formula, SciDAVis will assume it to be the body of a
function. That is, the following code will not work:
</p>
<pre class="programlisting" width="40">
a=1
a+a
</pre>
<p>
The statement in the first line means that the formula cannot
be evaluated as a single expression. Instead, the above code assigns
every row in the column the return value of the following function:
</p>
<pre class="programlisting" width="40">
def f():
a=1
a+a
</pre>
<p>
However, since Python does not implicitly interpret expressions as
something to return, this evaluates to nothing. The correct way
to enter formulas with statements in them is to explicitly return
something: </p>
<pre class="programlisting" width="40">
a=1
return a+a
</pre>
<p>There is a slight catch associated with this strategy. In a Notes
window, SciDAVis will allow you to <span class="emphasis"><em>evaluate</em></span>
variable assignments like <strong class="userinput"><code>ee=1.6021773e-19</code></strong>
without complaining - but this will not lead to the result presumably
intended, i.e. introducing a shortcut for the elementary charge to be
used within the notes window. What actually happens is this: SciDAVis
evaluates the function </p>
<pre class="programlisting" width="40">
def f():
ee=1.6021773e-19
</pre>
<p>
As mentioned in the Python introduction above, the function f has its
own variable scope and (unless it happens to be declared global) the
variable ee will only be visible within this scope (instead of the
Notes window's scope). The solution is simple: always
<span class="emphasis"><em>execute</em></span> things like assignments and function
definitions, never <span class="emphasis"><em>evaluate</em></span> them.</p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="Python-functions"></a>Mathematical Functions</h3></div></div></div>
<a class="indexterm" name="idp1396171892"></a><p>Python comes with some basic mathematical functions that are
automatically imported (if you use the <a class="link" href="sec-python.html#Python-init" title="The Initialization File">initialization file</a> shipped with SciDAVis).
Along with them, the constants e (Euler's number) and pi (the one and
only) are defined. Many, many more functions can be obtained by installing
<a class="ulink" href="https://www.scipy.org" target="_top">SciPy</a> and/or
<a class="ulink" href="http://pygsl.sourceforge.net" target="_top">PyGSL</a>.</p>
<div class="table">
<a name="idp1396174308"></a><p class="title"><b>Table 4.4. Supported Mathematical Functions</b></p>
<div class="table-contents"><table summary="Supported Mathematical Functions" width="100%" border="1">
<colgroup>
<col align="left" class="name">
<col align="justify" class="description">
</colgroup>
<thead><tr>
<th align="left">Name</th>
<th align="justify">Description</th>
</tr></thead>
<tbody>
<tr>
<td align="left">acos(x)</td>
<td align="justify">inverse cosine</td>
</tr>
<tr>
<td align="left">asin(x)</td>
<td align="justify">inverse sine</td>
</tr>
<tr>
<td align="left">atan(x)</td>
<td align="justify">inverse tangent</td>
</tr>
<tr>
<td align="left">atan2(y,x)</td>
<td align="justify">equivalent to atan(y/x), but more efficient</td>
</tr>
<tr>
<td align="left">ceil(x)</td>
<td align="justify">ceiling; smallest integer greater or equal to x</td>
</tr>
<tr>
<td align="left">cos(x)</td>
<td align="justify">cosine of x</td>
</tr>
<tr>
<td align="left">cosh(x)</td>
<td align="justify">hyperbolic cosine of x</td>
</tr>
<tr>
<td align="left">degrees(x)</td>
<td align="justify">convert angle from radians to degrees</td>
</tr>
<tr>
<td align="left">exp(x)</td>
<td align="justify">Exponential function: e raised to the power of x.</td>
</tr>
<tr>
<td align="left">fabs(x)</td>
<td align="justify">absolute value of x</td>
</tr>
<tr>
<td align="left">floor(x)</td>
<td align="justify">largest integer smaller or equal to x</td>
</tr>
<tr>
<td align="left">fmod(x,y)</td>
<td align="justify">remainder of integer division x/y</td>
</tr>
<tr>
<td align="left">frexp(x)</td>
<td align="justify">Returns the tuple (mantissa,exponent) such that
x=mantissa*(2**exponent) where exponent is an integer and 0.5
<=abs(m)<1.0</td>
</tr>
<tr>
<td align="left">hypot(x,y)</td>
<td align="justify">equivalent to sqrt(x*x+y*y)</td>
</tr>
<tr>
<td align="left">ldexp(x,y)</td>
<td align="justify">equivalent to x*(2**y)</td>
</tr>
<tr>
<td align="left">log(x)</td>
<td align="justify">natural (base e) logarithm of x</td>
</tr>
<tr>
<td align="left">log10(x)</td>
<td align="justify">decimal (base 10) logarithm of x</td>
</tr>
<tr>
<td align="left">modf(x)</td>
<td align="justify">return fractional and integer part of x as a
tuple</td>
</tr>
<tr>
<td align="left">pow(x,y)</td>
<td align="justify">x to the power of y; equivalent to x**y</td>
</tr>
<tr>
<td align="left">radians(x)</td>
<td align="justify">convert angle from degrees to radians</td>
</tr>
<tr>
<td align="left">sin(x)</td>
<td align="justify">sine of x</td>
</tr>
<tr>
<td align="left">sinh(x)</td>
<td align="justify">hyperbolic sine of x</td>
</tr>
<tr>
<td align="left">sqrt(x)</td>
<td align="justify">square root of x</td>
</tr>
<tr>
<td align="left">tan(x)</td>
<td align="justify">tangent of x</td>
</tr>
<tr>
<td align="left">tanh(x)</td>
<td align="justify">hyperbolic tangent of x</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="Python-API-Intro"></a>Accessing SciDAVis's functions from Python</h3></div></div></div>
<p>We will assume that you are using the <a class="link" href="sec-python.html#Python-init" title="The Initialization File">initialization file</a> shipped with
SciDAVis.</p>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idp1396194668"></a>Establishing contact</h4></div></div></div>
<p>Accessing the objects in your project is straight-forward,
</p>
<pre class="programlisting" width="40">
t = table("Table1")
m = matrix("Matrix1")
g = graph("Graph1")
n = note("Notes1")
</pre>
<p> as is creating new objects: </p>
<pre class="programlisting" width="40">
# create an empty table named "tony" with 5 rows and 2 columns:
t = newTable("tony", 5, 2)
# use defaults
t = newTable()
# create an empty matrix named "gina" with 42 rows and 23 columns:
m = newMatrix("gina", 42, 23)
# use defaults
m = newMatrix()
# create an empty graph window
g = newGraph()
# create an empty note named "momo"
n = newNote("momo")
# use defaults
n = newNote()
</pre>
<p>
New objects will always be added to the active folder.
The functions table, matrix, graph and note will start searching in the active folder and, failing this, continue with a depth-first recursive search of the project's root folder.
In order to access other folders, there are the functions
</p>
<pre class="programlisting" width="40">
f = activeFolder()
# and
f = rootFolder()
</pre>
<p>
which can be used to access subfolders and windows:
</p>
<pre class="programlisting" width="40">
f2 = f.folders()[number]
f2 = f.folder(name, caseSensitive=True, partialMatch=False)
t = f.table(name, recursive=False)
m = f.matrix(name, recursive=False)
g = f.graph(name, recursive=False)
n = f.note(name, recursive=False)
</pre>
<p>
If you supply True for the recursive argument, a depth-first recursive search of all sub-folders will be performed and the first match returned.</p>
<p>Also, every piece of code is executed in the context of an
object which you can access via the <code class="varname">self</code> variable. For example,
entering <strong class="userinput"><code>self.cell("t",i)</code></strong> as a column formula
is equivalent to the convenience function
<strong class="userinput"><code>col("t")</code></strong>.</p>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idp1396199980"></a>Working with Tables</h4></div></div></div>
<p>We'll assume that you have assigned some table to the variable
<code class="varname">t</code>. You can access its numeric cell values with
</p>
<pre class="programlisting" width="40">
t.cell(col, row)
# and
t.setCell(col, row, value)
</pre>
<p> Whenever you have to specify a column, you can use either the
column name (as a string) or the consecutive column number (starting
with 1). Row numbers also start with 1, just as they are displayed. If
you want to work with arbitrary texts or the textual representations
of numeric values, you can use </p>
<pre class="programlisting" width="40">
t.text(col, row)
# and
t.setText(col, row, string)
</pre>
<p> The number of columns and rows is accessed via </p>
<pre class="programlisting" width="40">
t.numRows()
t.numCols()
t.setNumRows(number)
t.setNumCols(number)
</pre>
<p> Column names can be read and written with </p>
<pre class="programlisting" width="40">
t.colName(number)
t.setColName(col, newName)
</pre>
<p> Normalize a single or all columns: </p>
<pre class="programlisting" width="40">
t.normalize(col)
t.normalize()
</pre>
<p> Import values from <code class="varname">file</code>, using
<code class="varname">sep</code> as separator char and ignoring
<code class="varname">ignore</code> lines at the head of the file. The flags
should be self-explanatory. </p>
<pre class="programlisting" width="40">
t.importASCII(file, sep="\t", ignore=0, renameCols=False, stripSpaces=True, simplifySpace=False, newTable=False)
</pre>
<p> After having changed some table values from a script, you will
likely want to update dependent Graphs: </p>
<pre class="programlisting" width="40">
t.notifyChanges()
</pre>
<p>As a simple example, let's set some column values without using
the dialog. </p>
<pre class="programlisting" width="40">
t = table("table1")
for i in range(1, t.numRows()+1):
t.setCell(1, i, i**2)
t.notifyChanges()
</pre>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idp1396206708"></a>Working with Matrices</h4></div></div></div>
<p>We'll assume that you have assigned some matrix to the variable
<code class="varname">m</code>. Accessing cell values is very similar to Table,
but since Matrix doesn't use column logic, row arguments are specified
before columns and obviously you can't use column name. </p>
<pre class="programlisting" width="40">
m.cell(row, col)
m.setCell(row, col, value)
m.text(row, col)
m.setText(row, col, string)
</pre>
<p> Also like with tables, there's </p>
<pre class="programlisting" width="40">
m.numRows()
# and
m.numCols()
</pre>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idp1396208820"></a>Plotting and Working with Graphs</h4></div></div></div>
<p>If you want to create a new Graph window for some data in table
table1, you can use the plot command: </p>
<pre class="programlisting" width="40">
g = plot(table, column, type)
</pre>
<p> <code class="varname">type</code> is a number between 0 and 10 and
specifies the desired plot type: </p>
<div class="variablelist"><dl class="variablelist compact">
<dt><span class="term">0.</span></dt>
<dd><p>Line</p></dd>
<dt><span class="term">1.</span></dt>
<dd><p>Symbols</p></dd>
<dt><span class="term">2.</span></dt>
<dd><p>Line and Symbols</p></dd>
<dt><span class="term">3.</span></dt>
<dd><p>Columns</p></dd>
<dt><span class="term">4.</span></dt>
<dd><p>Area</p></dd>
<dt><span class="term">5.</span></dt>
<dd><p>Pie</p></dd>
<dt><span class="term">6.</span></dt>
<dd><p>Vertical drop lines</p></dd>
<dt><span class="term">7.</span></dt>
<dd><p>Splines and Symbols</p></dd>
<dt><span class="term">8.</span></dt>
<dd><p>Vertical steps</p></dd>
<dt><span class="term">9.</span></dt>
<dd><p>Histogram</p></dd>
<dt><span class="term">10.</span></dt>
<dd><p>Rows</p></dd>
</dl></div>
<p> You can plot more than one column at once by giving
a Python tuple (see the <a class="ulink" href="https://docs.python.org/3/tutorial/index.html" target="_top">Python
Tutorial</a>) as an argument: </p>
<pre class="programlisting" width="40">
g = plot(table("table1"), (2,4,7), 2)
</pre>
<p>If you want to add a curve to an existing Graph window, you have
to choose the destination layer. Usually, </p>
<pre class="programlisting" width="40">
l = g.activeLayer()
</pre>
<p> will do the trick, but you can also select a layer by its number:
</p>
<pre class="programlisting" width="40">
l = g.layer(num)
</pre>
<p> You can then add or remove curves to or from this layer: </p>
<pre class="programlisting" width="40">
l.insertCurve(table, column, type=1)
l.insertCurve(table, Xcolumn, Ycolumn, type=1)
l.removeCurve(curveName)
l.removeCurve(curveNumber)
l.deleteFitCurves()
</pre>
<p> In case you need the number of curves on a layer, you can get it
with </p>
<pre class="programlisting" width="40">
l.numCurves()
</pre>
<p>Use the following functions to change the axis attachment of a curve:
</p>
<pre class="programlisting" width="40">
c = l.curve(number)
l.setCurveAxes(number, x-axis, y-axis)
c.setXAxis(x-axis)
c.setYAxis(y-axis)
</pre>
<p> where <code class="varname">number</code> is curve's index, <code class="varname">x-axis</code> is either <code class="varname">Layer.Bottom</code> or <code class="varname">Layer.Top</code> and <code class="varname">y-axis</code> is either <code class="varname">Layer.Left</code> or <code class="varname">Layer.Right</code> </p>
<pre class="programlisting" width="40">
l.setCurveAxes(0, Layer.Top, Layer.Right) # modify the first curve in the layer (curve index is 0)
c.setXAxis(Layer.Bottom)
c.setYAxis(Layer.Right) # attach curve c to the right Y axis
</pre>
<p>Layers and whole Graphs can be printed and exported from within
Python. Before you do this, you would probably want to change layer and axis
titles as well as legend texts: </p>
<pre class="programlisting" width="40">
l.setTitle(title)
l.setXTitle(Xtitle)
l.setYTitle(Ytitle)
l.setLegend(text)
</pre>
<p> You can also customize the scales of the different axes using: </p>
<pre class="programlisting" width="40">
l.setScale(int axis, double start, double end, double step=0.0, int majorTicks=5, int minorTicks=5, int type=0, bool inverted=False);
</pre>
<p>
where <code class="varname">axis</code> is one of <code class="varname">Layer.Left</code>, <code class="varname">Layer.Right</code>, <code class="varname">Layer.Bottom</code>, <code class="varname">Layer.Top</code>,
type specifies the desired scale type: <code class="varname">0</code> for <code class="varname">Linear</code> or <code class="varname">1</code> for <code class="varname">Log10</code>
and <code class="varname">step</code> defines the size of the interval between the major scale ticks. If not specified (default value is 0.0), the step size is calculated automatically. The other flags should be self-explanatory.</p>
<p>Now, here is how you can export a layer </p>
<pre class="programlisting" width="40">
l.print()
l.exportToSVG(filename)
l.exportToEPS(filename)
l.exportImage(filename, filetype="PNG", quality=100, transparent=False)
</pre>
<p> and a graph </p>
<pre class="programlisting" width="40">
g.print()
g.exportToSVG(filename)
g.exportToEPS(filename)
</pre>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idp1396231444"></a>Fitting</h4></div></div></div>
<p>Assuming you have a Graph named "graph1" with a curve entitled
"table1_2" (on its active layer), a minimal Fit example would be:
</p>
<pre class="programlisting" width="40">
f = GaussFit(graph("graph1").activeLayer(), "table1_2")
f.guessInitialValues()
f.fit()
</pre>
<p> This creates a new GaussFit object on the curve, lets it guess
the start parameters and does the fit. The following fit types are
supported: </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>LinearFit(layer, curve)</p></li>
<li class="listitem"><p>PolynomialFit(layer, curve, degree=2, legend=False)</p></li>
<li class="listitem"><p>ExponentialFit(layer, curve, growth=False)</p></li>
<li class="listitem"><p>TwoExpFit(layer, curve)</p></li>
<li class="listitem"><p>ThreeExpFit(layer, curve)</p></li>
<li class="listitem"><p>GaussFit(layer, curve)</p></li>
<li class="listitem"><p>GaussAmpFit(layer, curve)</p></li>
<li class="listitem"><p>LorentzFit(layer,curve)</p></li>
<li class="listitem"><p>SigmoidalFit(layer, curve)</p></li>
<li class="listitem">
<p>NonLinearFit(layer, curve)</p>
<pre class="programlisting" width="40">
f = NonLinearFit(layer, curve)
f.setParameters(name1, ...)
f.setFormula(formula_string)
</pre>
</li>
<li class="listitem">
<p>PluginFit(layer, curve)</p>
<pre class="programlisting" width="40">
f = PluginFit(layer, curve)
f.load(pluginName)
</pre>
</li>
</ul></div>
<p> For each of these, you can optionally restrict the X
range that will be used for the fit, like in </p>
<pre class="programlisting" width="40">
f = LinearFit(graph("graph1").activeLayer(), "table1_2", 2, 7)
f.fit()
</pre>
<p>After creating the Fit object and before calling its fit()
method, you can set a number of parameters that influence the fit:
</p>
<pre class="programlisting" width="80">
f.setDataFromCurve(curve) <em class="lineannotation"><span class="lineannotation">change data source</span></em>
f.setDataFromCurve(curve, graph) <em class="lineannotation"><span class="lineannotation">change data source</span></em>
f.setDataFromCurve(curve, from, to) <em class="lineannotation"><span class="lineannotation">change data source</span></em>
f.setDataFromCurve(curve, from, to, graph) <em class="lineannotation"><span class="lineannotation">change data source</span></em>
f.setInterval(from, to) <em class="lineannotation"><span class="lineannotation">change data range</span></em>
f.setInitialValue(number, value)
f.setInitialValues(value1, ...)
f.guessInitialValues()
f.setAlgorithm(algo) # algo = Fit.ScaledLevenbergMarquardt, Fit.UnscaledLevenbergMarquardt, Fit.NelderMeadSimplex
f.setYErrorSource(ErrorSource, colname) # ErrorSource can be: 0 / Fit.UnknownErrors, 1 / Fit.AssociatedErrors,
2 / Fit.PoissonErrors, or 3 / Fit.CustomErrors
f.setTolerance(tolerance)
f.setOutputPrecision(precision)
f.setMaximumIterations(number)
f.scaleErrors(yes = True)
f.setColor(qt.QColor("green")) <em class="lineannotation"><span class="lineannotation">change the color of the result fit curve to green (default color is red)</span></em>
</pre>
<p>After you've called fit(), you have a number of possibilities
for extracting the results: </p>
<pre class="programlisting" width="40">
f.results()
f.errors()
f.chiSquare()
f.rSquare()
f.dataSize()
f.numParameters()
f.parametersTable("params")
f.covarianceMatrix("cov")
</pre>
</div>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="Python-API"></a>API documentation</h3></div></div></div>
<p>Classes mentioned below that start with "Q" mostly belong to Qt and can be used via
PyQt (with the exception of classes starting with "Qwt", which belong to Qwt).
If you want to know what you can do with such classes (e.g. QIcon or QDateTime), see the
<a class="ulink" href="http://pyqt.sourceforge.net/Docs/PyQt4/classes.html" target="_top">PyQt
reference documentation</a>. It's also useful to know that you can call any QWidget
method exported by PyQt on instances of MDIWindow (and thus Table, Graph, Matrix and
Note).
</p>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idp1396245212"></a>class AbstractAspect (inherits QObject)</h4></div></div></div>
<p>A base class for content of a project. While currently the only AbstractAspect
accessible to you is Column, a future release will make more extensive usage of this;
probably with some revisions in the design, so only some basic functions are documented
(and supported) for now.</p>
<pre class="programlisting" width="80">
col = newTable("my-table",2,30).column("1")
col.setName("abc")
table("my-table").column("2").remove()
</pre>
<div class="variablelist"><dl class="variablelist compact">
<dt><span class="term">index()</span></dt>
<dd>Return the 0-based index of the Aspect in its sibling list.</dd>
<dt><span class="term">name()</span></dt>
<dd>Return the Aspect's name.</dd>
<dt><span class="term">setName(string)</span></dt>
<dd>Change the Aspect's name.</dd>
<dt><span class="term">comment()</span></dt>
<dd>Return comment attached to the Aspect.</dd>
<dt><span class="term">setComment(string)</span></dt>
<dd>Change the comment attached to the Aspect.</dd>
<dt><span class="term">icon()</span></dt>
<dd>Return the icon (a QIcon) used to designate the Aspect's type; for columns,
this is the data type icon in the table header.</dd>
<dt><span class="term">creationTime()</span></dt>
<dd>Return point in time the Aspect was created by the user (as a QDateTime).</dd>
<dt><span class="term">remove()</span></dt>
<dd>Remove Aspect from the project (can be undone using Edit->Undo menu).</dd>
<dt><span class="term">signal void aspectDescriptionAboutToChange(const AbstractAspect*)</span></dt>
<dd>Emitted before the description (name or comment) is changed.</dd>
<dt><span class="term">signal void aspectDescriptionChanged(const AbstractAspect*)</span></dt>
<dd>Emitted after the description (name or comment) has changed.</dd>
<dt><span class="term">signal void aspectAboutToBeRemoved(const AbstractAspect*)</span></dt>
<dd>Emitted before the Aspect is removed.</dd>
</dl></div>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idp1396254452"></a>class Column (inherits AbstractAspect)</h4></div></div></div>
<p>Represents a column in a table.</p>
<p>In addition to the valueAt()/setValueAt() interface described below, starting with
SciDAVis 0.2.4, Y columns support
getting/setting row values via the values in the corresponding X column. This is done
using Python's item access notation for sequence types (as in col["abc"]).</p>
<pre class="programlisting" width="80">
# basic access
tab = newTable("tabula1",2,20)
col = tab.column("1")
col.setValueAt(1, 123.0)
print col.valueAt(1)
# replacing multiple values at once is more efficient than setting them one at a time
col.replaceValues(5, [11.2, 12.3, 23.4, 34.5, 45.6])
# set a value in the second column based on the content of the first one
# (needs SciDAVis >= 0.2.4)
tab.column("2")[23.4] = 46.8
dest = table("tabula1").column("2")
# also, copying from another column can be done in one go:
dest.copy(col, 5, 2, 10)
</pre>
<div class="variablelist"><dl class="variablelist compact">
<dt><span class="term">columnMode()</span></dt>
<dd>A string designating the data type; one of "Numeric", "Text", "Month",
"Day" or "DateTime".</dd>
<dt><span class="term">setColumnMode(string)</span></dt>
<dd>Change the column's data type; argument must be one of "Numeric", "Text",
"Month", "Day" or "DateTime".</dd>
<dt><span class="term">copy(Column)</span></dt>
<dd>Copy complete content of other column, which must have the same data type (mode).
Returns a boolean indicating success or failure.</dd>
<dt><span class="term">copy(Column,int,int,int)</span></dt>
<dd>copy(source, source_start, dest_start, num_rows) copies num_rows values from source,
starting to read at row source_start and to write at row dest_start.</dd>
<dt><span class="term">rowCount()</span></dt>
<dd>Number of rows in the column.</dd>
<dt><span class="term">insertRows(int, int)</span></dt>
<dd>insertRows(before, count) insert count empty rows before row numbered before</dd>
<dt><span class="term">removeRows(int, int)</span></dt>
<dd>removeRows(first, count) removes count rows starting with row numbered first</dd>
<dt><span class="term">plotDesignation()</span></dt>
<dd>Return a string representing the plot designation of the column; one of "noDesignation", "X", "Y", "Z", "xErr" or "yErr".</dd>
<dt><span class="term">setPlotDesignation(string)</span></dt>
<dd>Set the plot designation. The argument must be one of "noDesignation", "X", "Y", "Z", "xErr" or "yErr".</dd>
<dt><span class="term">clear()</span></dt>
<dd>Clear content of all cells in the column, marking them as empty/invalid.</dd>
<dt><span class="term">isInvalid(int)</span></dt>
<dd>Returns boolean indicating whether the given row is marked as empty/invalid.</dd>
<dt><span class="term">formula(int)</span></dt>
<dd>Return formula used to compute the cell value in the given row.</dd>
<dt><span class="term">setFormula(int, string)</span></dt>
<dd>Sets formula for the given row to string.</dd>
<dt><span class="term">clearFormulas()</span></dt>
<dd>Discard all formulas associated with cells.</dd>
<dt><span class="term">valueAt(int)</span></dt>
<dd>Retrieve value of the specified cell (given by 0-based index), assuming that the column has columnMode() == "Numeric".</dd>
<dt><span class="term">setValueAt(int, double)</span></dt>
<dd>Set value of specified cell (given by 0-based index), assuming that the column has columnMode() == "Numeric".</dd>
<dt><span class="term">replaceValues(int, list of double values)</span></dt>
<dd>Mass-update cells starting at the indicated row, assuming that the column's columnMode() is one of "Numeric". Compared with setValueAt(), this has the advantage of being much more efficient; particularly if the column has dependant plots.</dd>
<dt><span class="term">textAt(int)</span></dt>
<dd>Retrieve value of the specified cell (given by 0-based index), assuming that the column has columnMode() == "Text".</dd>
<dt><span class="term">setTextAt(int, string)</span></dt>
<dd>Set value of specified cell (given by 0-based index), assuming that the column has columnMode() == "Text".</dd>
<dt><span class="term">replaceTexts(int, list of strings)</span></dt>
<dd>Mass-update cells starting at the indicated row, assuming that the column has columnMode() == "Text". Compared with setTextAt(), this has the advantage of being much more efficient; particularly if the column has dependant plots.</dd>
<dt><span class="term">dateAt(int)</span></dt>
<dd>Retrieve value of the specified cell (given by 0-based index), assuming that the column's columnMode() is one of "Month", "Day", "DateTime".</dd>
<dt><span class="term">setDateAt(int, QDate)</span></dt>
<dd>Set value of specified cell (given by 0-based index), assuming that the column's columnMode() is one of "Month", "Day", "DateTime".</dd>
<dt><span class="term">timeAt(int)</span></dt>
<dd>Retrieve value of the specified cell (given by 0-based index), assuming that the column has columnMode() == "DateTime".</dd>
<dt><span class="term">setTimeAt(int, QTime)</span></dt>
<dd>Set value of specified cell (given by 0-based index), assuming that the column has columnMode() == "DateTime".</dd>
<dt><span class="term">dateTimeAt(int)</span></dt>
<dd>Retrieve value of the specified cell (given by 0-based index), assuming that the column's columnMode() is one of "Month", "Day", "DateTime".</dd>
<dt><span class="term">setDateTimeAt(int, QDateTime)</span></dt>
<dd>Set value of specified cell (given by 0-based index), assuming that the column's columnMode() is one of "Month", "Day", "DateTime".</dd>
<dt><span class="term">replaceDateTimes(int, list of QDateTime values)</span></dt>
<dd>Mass-update cells starting at the indicated row, assuming that the column's columnMode() is one of "Month", "Day", "DateTime". Compared with setDateTimeAt(), this has the advantage of being much more efficient; particularly if the column has dependant plots.</dd>
<dt><span class="term">x()</span></dt>
<dd>Returns the X Column associated with this (Y, xErr or yErr) column.</dd>
<dt><span class="term">y()</span></dt>
<dd>Returns the Y Column associated with this (xErr or yErr) column, or the first Y column associated with this X column.</dd>
</dl></div>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idp1396277980"></a>class MDIWindow (inherits QWidget)</h4></div></div></div>
<p>Base class of Table, Matrix, Graph and Note. A redesigned analogue under the name of "Part" (inheriting from AbstractAspect) is under development; it should be possible to provide a backwards-compatible interface, though.</p>
<pre class="programlisting" width="80">
tmp = newTable("temp1", 2, 10)
tmp.setWindowLabel("a temporary table")
tmp.setCaptionPolicy(MDIWindow.Label)
# ...
tmp.confirmClose(False)
tmp.close()
</pre>
<div class="variablelist"><dl class="variablelist compact">
<dt><span class="term">name()</span></dt>
<dd>Return the window's name (added in SciDAVis 0.2.3).</dd>
<dt><span class="term">setName(string)</span></dt>
<dd>Set window's name. IMPORTANT: This was added in SciDAVis 0.2.3, but unfortunately is BROKEN in this release. Usable starting with SciDAVis 0.2.4.</dd>
<dt><span class="term">windowLabel()</span></dt>
<dd>Returns the comment associated with the window (yes, the confusing name will be fixed in a future release).</dd>
<dt><span class="term">setWindowLabel(string)</span></dt>
<dd>Set comment associated with the window (yes, the confusing name will be fixed in a future release).</dd>
<dt><span class="term">captionPolicy()</span></dt>
<dd>Return caption policy (i.e., what to display in the title bar). One of the integer constants MDIWindow.Name, MDIWindow.Label or MDIWindow.Both.</dd>
<dt><span class="term">setCaptionPolicy(int)</span></dt>
<dd>Set caption policy (i.e., what to display in the title bar). Must be one of the integer constants MDIWindow.Name, MDIWindow.Label or MDIWindow.Both.</dd>
<dt><span class="term">folder()</span></dt>
<dd>Return the folder this window belongs to (an object of class Folder).</dd>
<dt><span class="term">confirmClose(boolean)</span></dt>
<dd>Set a flag indicating whether the user should be given the opportunity to cancel removing the window or minimize it instead when trying to close it. When False, close() will remove the window without asking for confirmation, which is useful for temporary objects created by a script.</dd>
<dt><span class="term">clone()</span></dt>
<dd>Returns a copy of this window.
Added in SciDAVis 0.2.4.
</dd>
</dl></div>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idp1396286412"></a>class Table (inherits MDIWindow)</h4></div></div></div>
<p>Class of table (spreadsheet) windows.</p>
<pre class="programlisting" width="80">
tab = newTable("tabula",2,10)
for j in range(0, tab.numCols()):
for i in range(0, tab.numRows()):
tab.column(j).setValueAt(i,i*j)
tab.normalize()
</pre>
<div class="variablelist"><dl class="variablelist compact">
<dt><span class="term">numRows()</span></dt>
<dd>Returns the number of rows of the table.</dd>
<dt><span class="term">numCols()</span></dt>
<dd>Returns the number of columns of the table.</dd>
<dt><span class="term">setNumRows(int)</span></dt>
<dd>Sets the number of rows of the table.</dd>
<dt><span class="term">setNumCols(int)</span></dt>
<dd>Sets the number of columns of the table.</dd>
<dt><span class="term">column(string or int)</span></dt>
<dd>Returns Column indicated by name (preferred) or 0-based index. For the
latter form, keep in mind that inserting, removing or moving columns will break
scripts which refer to a specific column by index.
Starting with SciDAVis 0.2.4, columns may also be accessed using the []
operator, i.e. using table("table name")[column name or index].
</dd>
<dt><span class="term">text(string or int, int)</span></dt>
<dd>DEPRECATED. Use column(col).textAt(row) or str(column(col).valueAt(row)) instead (depending on the column's mode).
CAVEAT: text() indexes are 1-based, while column() and textAt() use more conventional 0-based indexes!</dd>
<dt><span class="term">cell(string or int, int)</span></dt>
<dd>DEPRECATED. Use column(col).valueAt(row) instead.
CAVEAT: cell() indexes are 1-based, while column() and valueAt() use more conventional 0-based indexes!</dd>
<dt><span class="term">setText(string or int, int, string</span></dt>
<dd>DEPRECATED. Use column(col).setTextAt(row,value) instead.
CAVEAT: setText() indexes are 1-based, while column() and setTextAt() use more conventional 0-based indexes!</dd>
<dt><span class="term">setCell(string or int, int, double</span></dt>
<dd>DEPRECATED. Use column(col).setValueAt(row,value) instead.
CAVEAT: setCell() indexes are 1-based, while column() and setValueAt() use more conventional 0-based indexes!</dd>
<dt><span class="term">colName(int)</span></dt>
<dd>DEPRECATED. Use column(col).name() instead.</dd>
<dt><span class="term">setColName(int,string)</span></dt>
<dd>DEPRECATED. Use column(col).setName(name) instead.</dd>
<dt><span class="term">setComment(int,string)</span></dt>
<dd>DEPRECATED. Use column(col).setComment(text) instead.</dd>
<dt><span class="term">setCommand(string or int, string)</span></dt>
<dd>Set formula indicated by first argument to the text given in the second argument.</dd>
<dt><span class="term">notifyChanges()</span></dt>
<dd>DEPRECATED. Update notifications are now done automatically.</dd>
<dt><span class="term">importASCII(string, string, int, bool, bool, bool)</span></dt>
<dd>importASCII(file, separator="\t", ignored_lines=0, rename_cols=False, strip_spaces=True, simplify_spaces=False)
imports file into this table, skipping ignored_lines lines at the beginning and
splitting the rest into columns according to the given separator and flags.</dd>
<dt><span class="term">exportASCII(string, string, bool, bool)</span></dt>
<dd>exportASCII(file, separator="\t", with_comments=False, selection_only=False)
exports this table to the given file with the column separator given in the second argument;
optionally including column comments and optionally exporting only selected cells.</dd>
<dt><span class="term">normalize(string or int)</span></dt>
<dd>Normalize specified column to a maximum cell value of one.</dd>
<dt><span class="term">normalize()</span></dt>
<dd>Normalize all columns in table to a maximum cell value of one.</dd>
<dt><span class="term">sortColumn(string or int, int=0)</span></dt>
<dd>Sort column indicated in the first argument. The second argument selects
the sorting order; 0 means ascending, 1 means descending.</dd>
<dt><span class="term">sort(int=0, int=0, string="")</span></dt>
<dd>sort(type, order, leading_column) sorts all columns in the table either separately
(type=0) or together (type=1) with the leading column given by name. The second argument selects
the sorting order; 0 means ascending, 1 means descending.</dd>
<dt><span class="term">sortColumns(list of strings, int, int, string)</span></dt>
<dd>sortColumns(columns, type=0, order=0, leading_column="") sorts columns given as a tuple of
names either separately (type=0) or together (type=1) with the leading column given by name.
The third argument selects the sorting order; 0 means ascending, 1 means descending.</dd>
</dl></div>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="idp1396304364"></a>class Matrix (inherits MDIWindow)</h4></div></div></div>
<p>Class of matrix windows.</p>
<pre class="programlisting" width="80">
mat = newMatrix("mat", 10, 20)
mat.setCoordinates(100,2000,100,1000)
mat.setFormula("i*j")
mat.recalculate()
</pre>
<div class="variablelist"><dl class="variablelist compact">
<dt><span class="term">numRows()</span></dt>
<dd>Returns the number of rows in the matrix.</dd>
<dt><span class="term">numCols()</span></dt>
<dd>Returns the number of columns in the matrix.</dd>
<dt><span class="term">setNumRows(int)</span></dt>
<dd>Changes the number of rows in the matrix.</dd>
<dt><span class="term">setNumCols(int)</span></dt>
<dd>Changes the number of columns in the matrix.</dd>
<dt><span class="term">setDimensions(int,int)</span></dt>
<dd>setDimensions(rows, cols) changes the number of rows and columns simultaneously.</dd>
<dt><span class="term">cell(int,int)</span></dt>
<dd>cell(row,column) returns the content of the indicated cell as a number.</dd>
<dt><span class="term">text(int,int)</span></dt>
<dd>text(row,column) returns the content of the indicated cell as its textual representation.</dd>
<dt><span class="term">setCell(int,int,double)</span></dt>
<dd>setCell(row,column,value) changes the content of the indicated cell to the indicated numeric value.</dd>