-
Notifications
You must be signed in to change notification settings - Fork 8
/
__init__.py
3346 lines (2708 loc) · 115 KB
/
__init__.py
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
# -*- coding: utf-8 -*-
"""
This is a procedural interface to the GR plotting library,
which may be imported directly, e.g.:
import gr
"""
import os
import sys
import numpy as np
from numpy import array, ndarray, float64, int32, empty, prod
from ctypes import c_int, c_double, c_char_p, c_void_p, c_uint8
from ctypes import byref, POINTER, addressof, CDLL, CFUNCTYPE
from ctypes import create_string_buffer, cast
from sys import version_info, platform
from platform import python_implementation
# local library
try:
from gr._version import __version__, __revision__
except ImportError:
try:
# If the _version module is not found, this might be a git clone and
# vcversioner might find the version. Alternatively it might be a
# source archive with no git information, in which case we do not want
# vcversioner to print an error and exit. Also, we do not want
# vcversioner to write out a version file, as this path might be read
# only.
import vcversioner
vcversioner._print = lambda *args, **kwargs: None
_version = vcversioner.find_version(version_file=None)
__version__ = _version.version
__revision__ = _version.sha
except ImportError:
__version__ = 'unknown'
__revision__ = None
except SystemExit:
__version__ = 'unknown'
__revision__ = None
from gr.runtime_helper import load_runtime, register_gksterm
# Detect whether this is a site-package installation
if os.path.isdir(os.path.join(os.path.dirname(__file__), "fonts")):
# Set GRDIR environment accordingly to site-package installation.
# (needed for finding GKSTerm on OSX)
os.environ["GRDIR"] = os.getenv("GRDIR",
os.path.realpath(os.path.dirname(__file__)))
os.environ["GKS_FONTPATH"] = os.getenv("GKS_FONTPATH", os.environ["GRDIR"])
# The Python wrapper only passes UTF-8 encoded strings to the GR runtime
os.environ['GKS_ENCODING'] = 'utf-8'
_impl = python_implementation()
_mime_type = None
try:
from IPython.display import clear_output, display, SVG, Image, HTML
from base64 import b64encode
except ImportError:
clear_output = None
class floatarray:
def __init__(self, n, a):
if isinstance(a, ndarray):
if _impl == 'PyPy':
self.array = array(a, float64)
self.data = cast(self.array.__array_interface__['data'][0],
POINTER(c_double))
else:
self.array = array(a, c_double)
self.data = self.array.ctypes.data_as(POINTER(c_double))
else:
self.data = (c_double * n)()
status = 0
for i in range(n):
try:
self.data[i] = a[i]
except:
if not status:
status = 1
print('Float array lookup failure')
self.data[i] = 0
class intarray:
def __init__(self, n, a):
if isinstance(a, ndarray):
if _impl == 'PyPy':
self.array = array(a, int32)
self.data = cast(self.array.__array_interface__['data'][0],
POINTER(c_int))
else:
self.array = array(a, c_int)
self.data = self.array.ctypes.data_as(POINTER(c_int))
else:
self.data = (c_int * n)()
status = 0
for i in range(n):
try:
self.data[i] = a[i]
except:
if not status:
status = 1
print('Integer array lookup failure')
self.data[i] = 0
class uint8array:
def __init__(self, a):
if _impl == 'PyPy':
self.array = array(a, uint8)
self.data = cast(self.array.__array_interface__['data'][0],
POINTER(c_uint8))
else:
self.array = array(a, c_uint8)
self.data = self.array.ctypes.data_as(POINTER(c_uint8))
class nothing:
def __init__(self):
self.array = None
self.data = None
def char(string):
"""
Create a C string from a Python string, bytes or unicode object.
"""
if version_info[0] == 2:
string_is_binary = not isinstance(string, unicode)
else:
string_is_binary = isinstance(string, bytes)
# first ensure string is not binary...
if string_is_binary:
try:
string = string.decode('utf-8')
except:
string = string.decode('latin-1')
# ... then encode it as utf-8, moving any encoding issues from C to Python.
binary_string = string.encode('utf-8')
c_string = create_string_buffer(binary_string)
return cast(c_string, c_char_p)
def opengks():
__gr.gr_opengks()
def closegks():
__gr.gr_closegks()
def inqdspsize():
mwidth = c_double()
mheight = c_double()
width = c_int()
height = c_int()
__gr.gr_inqdspsize(byref(mwidth), byref(mheight), byref(width), byref(height))
return [mwidth.value, mheight.value, width.value, height.value]
def openws(workstation_id, connection, workstation_type):
"""
Open a graphical workstation.
**Parameters:**
`workstation_id` :
A workstation identifier.
`connection` :
A connection identifier.
`workstation_type` :
The desired workstation type.
Available workstation types:
+-------------+------------------------------------------------------+
| 5|Workstation Independent Segment Storage |
+-------------+------------------------------------------------------+
| 7, 8|Computer Graphics Metafile (CGM binary, clear text) |
+-------------+------------------------------------------------------+
| 41|Windows GDI |
+-------------+------------------------------------------------------+
| 51|Mac Quickdraw |
+-------------+------------------------------------------------------+
| 61 - 64|PostScript (b/w, color) |
+-------------+------------------------------------------------------+
| 101, 102|Portable Document Format (plain, compressed) |
+-------------+------------------------------------------------------+
| 210 - 213|X Windows |
+-------------+------------------------------------------------------+
| 214|Sun Raster file (RF) |
+-------------+------------------------------------------------------+
| 215, 218|Graphics Interchange Format (GIF87, GIF89) |
+-------------+------------------------------------------------------+
| 216|Motif User Interface Language (UIL) |
+-------------+------------------------------------------------------+
| 320|Windows Bitmap (BMP) |
+-------------+------------------------------------------------------+
| 321|JPEG image file |
+-------------+------------------------------------------------------+
| 322|Portable Network Graphics file (PNG) |
+-------------+------------------------------------------------------+
| 323|Tagged Image File Format (TIFF) |
+-------------+------------------------------------------------------+
| 370|Xfig vector graphics file |
+-------------+------------------------------------------------------+
| 371|Gtk |
+-------------+------------------------------------------------------+
| 380|wxWidgets |
+-------------+------------------------------------------------------+
| 381|Qt4 |
+-------------+------------------------------------------------------+
| 382|Scaleable Vector Graphics (SVG) |
+-------------+------------------------------------------------------+
| 390|Windows Metafile |
+-------------+------------------------------------------------------+
| 400|Quartz |
+-------------+------------------------------------------------------+
| 410|Socket driver |
+-------------+------------------------------------------------------+
| 415|0MQ driver |
+-------------+------------------------------------------------------+
| 420|OpenGL |
+-------------+------------------------------------------------------+
| 430|HTML5 Canvas |
+-------------+------------------------------------------------------+
"""
__gr.gr_openws(c_int(workstation_id), char(connection), c_int(workstation_type))
def closews(workstation_id):
"""
Close the specified workstation.
**Parameters:**
`workstation_id` :
A workstation identifier.
"""
__gr.gr_closews(c_int(workstation_id))
def activatews(workstation_id):
"""
Activate the specified workstation.
**Parameters:**
`workstation_id` :
A workstation identifier.
"""
__gr.gr_activatews(c_int(workstation_id))
def deactivatews(workstation_id):
"""
Deactivate the specified workstation.
**Parameters:**
`workstation_id` :
A workstation identifier.
"""
__gr.gr_deactivatews(c_int(workstation_id))
def clearws():
if isinline() and clear_output:
clear_output(wait=True)
__gr.gr_clearws()
def updatews():
__gr.gr_updatews()
def _assertEqualLength(*args):
if args and all(len(args[0]) == len(arg) for arg in args):
return len(args[0])
else:
raise AttributeError("Sequences must have same length.")
def polyline(x, y):
"""
Draw a polyline using the current line attributes, starting from the
first data point and ending at the last data point.
**Parameters:**
`x` :
A list containing the X coordinates
`y` :
A list containing the Y coordinates
The values for `x` and `y` are in world coordinates. The attributes that
control the appearance of a polyline are linetype, linewidth and color
index.
"""
n = _assertEqualLength(x, y)
_x = floatarray(n, x)
_y = floatarray(n, y)
__gr.gr_polyline(c_int(n), _x.data, _y.data)
def quiver(nx, ny, x, y, u, v, color):
"""
Draw a quiver plot on a grid of nx*ny points.
**Parameters:**
`nx` :
The number of points along the x-axis of the grid
`nx` :
The number of points along the y-axis of the grid
`x` :
A list containing the X coordinates
`y` :
A list containing the Y coordinates
`u` :
A list containing the U component for each point on the grid
`v` :
A list containing the V component for each point on the grid
`color` :
A bool to indicate whether or not the arrows should be colored using
the current colormap
The values for `x` and `y` are in world coordinates.
"""
_x = floatarray(nx, x)
_y = floatarray(ny, y)
_u = floatarray(nx * ny, u)
_v = floatarray(nx * ny, v)
__gr.gr_quiver(c_int(nx), c_int(ny), _x.data, _y.data, _u.data, _v.data, c_int(1 if color else 0))
def polymarker(x, y):
"""
Draw marker symbols centered at the given data points.
**Parameters:**
`x` :
A list containing the X coordinates
`y` :
A list containing the Y coordinates
The values for `x` and `y` are in world coordinates. The attributes that
control the appearance of a polymarker are marker type, marker size
scale factor and color index.
"""
n = _assertEqualLength(x, y)
_x = floatarray(n, x)
_y = floatarray(n, y)
__gr.gr_polymarker(c_int(n), _x.data, _y.data)
def text(x, y, string):
"""
Draw a text at position `x`, `y` using the current text attributes.
**Parameters:**
`x` :
The X coordinate of starting position of the text string
`y` :
The Y coordinate of starting position of the text string
`string` :
The text to be drawn
The values for `x` and `y` are in normalized device coordinates.
The attributes that control the appearance of text are text font and precision,
character expansion factor, character spacing, text color index, character
height, character up vector, text path and text alignment.
"""
__gr.gr_text(c_double(x), c_double(y), char(string))
def inqtext(x, y, string):
tbx = (c_double * 4)()
tby = (c_double * 4)()
__gr.gr_inqtext(c_double(x), c_double(y), char(string), tbx, tby)
return [[tbx[0], tbx[1], tbx[2], tbx[3]],
[tby[0], tby[1], tby[2], tby[3]]]
def fillarea(x, y):
"""
Allows you to specify a polygonal shape of an area to be filled.
**Parameters:**
`x` :
A list containing the X coordinates
`y` :
A list containing the Y coordinates
The attributes that control the appearance of fill areas are fill area interior
style, fill area style index and fill area color index.
"""
n = _assertEqualLength(x, y)
_x = floatarray(n, x)
_y = floatarray(n, y)
__gr.gr_fillarea(c_int(n), _x.data, _y.data)
def cellarray(xmin, xmax, ymin, ymax, dimx, dimy, color):
"""
Display rasterlike images in a device-independent manner. The cell array
function partitions a rectangle given by two corner points into DIMX X DIMY
cells, each of them colored individually by the corresponding color index
of the given cell array.
**Parameters:**
`xmin`, `ymin` :
Lower left point of the rectangle
`xmax`, `ymax` :
Upper right point of the rectangle
`dimx`, `dimy` :
X and Y dimension of the color index array
`color` :
Color index array
The values for `xmin`, `xmax`, `ymin` and `ymax` are in world coordinates.
"""
_color = intarray(dimx * dimy, color)
__gr.gr_cellarray(c_double(xmin), c_double(xmax), c_double(ymin), c_double(ymax),
c_int(dimx), c_int(dimy), c_int(1), c_int(1),
c_int(dimx), c_int(dimy), _color.data)
def polarcellarray(x_org, y_org, phimin, phimax, rmin, rmax, dimphi, dimr, color):
"""
Display a two dimensional color index array mapped to a disk using polar
coordinates.
**Parameters:**
`x_org`, `y_org` :
X and Y coordinate of the disk center in world coordinates
`phimin`, `phimax` :
start and end angle of the disk sector in degrees
`rmin`, `rmax` :
inner and outer radius of the (punctured) disk in world coordinates
`dimphi`, `dimr` :
Phi (X) and R (Y) dimension of the color index array
`color` color index array
The two dimensional color index array is mapped to the resulting image by
interpreting the X-axis of the array as the angle and the Y-axis as the raidus.
The center point of the resulting disk is located at `x_org`, `y_org` and the
radius of the disk is `rmax`.
To draw a contiguous array as a complete disk use:
gr.polarcellarray(x_org, y_org, 0, 360, 0, rmax, dimphi, dimr, color)
The additional parameters to the function can be used to further control the
mapping from polar to cartesian coordinates.
If `rmin` is greater than 0 the input data is mapped to a punctured disk (or
annulus) with an inner radius of `rmin` and an outer radius `rmax`. If `rmin`
is greater than `rmax` the Y-axis of the array is reversed.
The parameter `phimin` and `phimax` can be used to map the data to a sector
of the (punctured) disk starting at `phimin` and ending at `phimax`. If
`phimin` is greater than `phimax` the X-axis is reversed. The visible sector
is the one starting in mathematically positive direction (counterclockwise)
at the smaller angle and ending at the larger angle. An example of the four
possible options can be found below:
+-----------+-----------+---------------------------------------------------+
|**phimin** |**phimax** |**Result** |
+-----------+-----------+---------------------------------------------------+
|90 |270 |Left half visible, mapped counterclockwise |
+-----------+-----------+---------------------------------------------------+
|270 |90 |Left half visible, mapped clockwise |
+-----------+-----------+---------------------------------------------------+
|-90 |90 |Right half visible, mapped counterclockwise |
+-----------+-----------+---------------------------------------------------+
|90 |-90 |Right half visible, mapped clockwise |
+-----------+-----------+---------------------------------------------------+
"""
_color = intarray(dimr * dimphi, color)
__gr.gr_polarcellarray(c_double(x_org), c_double(y_org), c_double(phimin), c_double(phimax),
c_double(rmin), c_double(rmax), c_int(dimphi), c_int(dimr),
c_int(1), c_int(1), c_int(dimphi), c_int(dimr), _color.data)
def spline(px, py, m, method):
"""
Generate a cubic spline-fit, starting from the first data point and
ending at the last data point.
**Parameters:**
`x` :
A list containing the X coordinates
`y` :
A list containing the Y coordinates
`m` :
The number of points in the polygon to be drawn (`m` > len(`x`))
`method` :
The smoothing method
The values for `x` and `y` are in world coordinates. The attributes that
control the appearance of a spline-fit are linetype, linewidth and color
index.
If `method` is > 0, then a generalized cross-validated smoothing spline is calculated.
If `method` is 0, then an interpolating natural cubic spline is calculated.
If `method` is < -1, then a cubic B-spline is calculated.
"""
n = _assertEqualLength(px, py)
_px = floatarray(n, px)
_py = floatarray(n, py)
__gr.gr_spline(c_int(n), _px.data, _py.data, c_int(m), c_int(method))
def gridit(xd, yd, zd, nx, ny):
nd = _assertEqualLength(xd, yd, zd)
_xd = floatarray(nd, xd)
_yd = floatarray(nd, yd)
_zd = floatarray(nd, zd)
x = (c_double * nx)()
y = (c_double * ny)()
z = (c_double * (nx * ny))()
__gr.gr_gridit(c_int(nd), _xd.data, _yd.data, _zd.data,
c_int(nx), c_int(ny), x, y, z)
return [x[:], y[:], z[:]]
def setlinetype(style):
"""
Specify the line style for polylines.
**Parameters:**
`style` :
The polyline line style
The available line types are:
+---------------------------+----+---------------------------------------------------+
|LINETYPE_SOLID | 1|Solid line |
+---------------------------+----+---------------------------------------------------+
|LINETYPE_DASHED | 2|Dashed line |
+---------------------------+----+---------------------------------------------------+
|LINETYPE_DOTTED | 3|Dotted line |
+---------------------------+----+---------------------------------------------------+
|LINETYPE_DASHED_DOTTED | 4|Dashed-dotted line |
+---------------------------+----+---------------------------------------------------+
|LINETYPE_DASH_2_DOT | -1|Sequence of one dash followed by two dots |
+---------------------------+----+---------------------------------------------------+
|LINETYPE_DASH_3_DOT | -2|Sequence of one dash followed by three dots |
+---------------------------+----+---------------------------------------------------+
|LINETYPE_LONG_DASH | -3|Sequence of long dashes |
+---------------------------+----+---------------------------------------------------+
|LINETYPE_LONG_SHORT_DASH | -4|Sequence of a long dash followed by a short dash |
+---------------------------+----+---------------------------------------------------+
|LINETYPE_SPACED_DASH | -5|Sequence of dashes double spaced |
+---------------------------+----+---------------------------------------------------+
|LINETYPE_SPACED_DOT | -6|Sequence of dots double spaced |
+---------------------------+----+---------------------------------------------------+
|LINETYPE_DOUBLE_DOT | -7|Sequence of pairs of dots |
+---------------------------+----+---------------------------------------------------+
|LINETYPE_TRIPLE_DOT | -8|Sequence of groups of three dots |
+---------------------------+----+---------------------------------------------------+
"""
__gr.gr_setlinetype(c_int(style))
def inqlinetype():
ltype = c_int()
__gr.gr_inqlinetype(byref(ltype))
return ltype.value
def setlinewidth(width):
"""
Define the line width of subsequent polyline output primitives.
**Parameters:**
`width` :
The polyline line width scale factor
The line width is calculated as the nominal line width generated
on the workstation multiplied by the line width scale factor.
This value is mapped by the workstation to the nearest available line width.
The default line width is 1.0, or 1 times the line width generated on the graphics device.
"""
__gr.gr_setlinewidth(c_double(width))
def inqlinewidth():
width = c_double()
__gr.gr_inqlinewidth(byref(width))
return width.value
def setlinecolorind(color):
"""
Define the color of subsequent polyline output primitives.
**Parameters:**
`color` :
The polyline color index (COLOR < 1256)
"""
__gr.gr_setlinecolorind(c_int(color))
def inqlinecolorind():
coli = c_int()
__gr.gr_inqlinecolorind(byref(coli))
return coli.value
def setmarkertype(style):
"""
Specifiy the marker type for polymarkers.
**Parameters:**
`style` :
The polymarker marker type
The available marker types are:
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_DOT | 1|Smallest displayable dot |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_PLUS | 2|Plus sign |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_ASTERISK | 3|Asterisk |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_CIRCLE | 4|Hollow circle |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_DIAGONAL_CROSS | 5|Diagonal cross |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_SOLID_CIRCLE | -1|Filled circle |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_TRIANGLE_UP | -2|Hollow triangle pointing upward |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_SOLID_TRI_UP | -3|Filled triangle pointing upward |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_TRIANGLE_DOWN | -4|Hollow triangle pointing downward |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_SOLID_TRI_DOWN | -5|Filled triangle pointing downward |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_SQUARE | -6|Hollow square |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_SOLID_SQUARE | -7|Filled square |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_BOWTIE | -8|Hollow bowtie |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_SOLID_BOWTIE | -9|Filled bowtie |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_HGLASS | -10|Hollow hourglass |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_SOLID_HGLASS | -11|Filled hourglass |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_DIAMOND | -12|Hollow diamond |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_SOLID_DIAMOND | -13|Filled Diamond |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_STAR | -14|Hollow star |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_SOLID_STAR | -15|Filled Star |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_TRI_UP_DOWN | -16|Hollow triangles pointing up and down overlaid |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_SOLID_TRI_RIGHT | -17|Filled triangle point right |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_SOLID_TRI_LEFT | -18|Filled triangle pointing left |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_HOLLOW PLUS | -19|Hollow plus sign |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_SOLID PLUS | -20|Solid plus sign |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_PENTAGON | -21|Pentagon |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_HEXAGON | -22|Hexagon |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_HEPTAGON | -23|Heptagon |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_OCTAGON | -24|Octagon |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_STAR_4 | -25|4-pointed star |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_STAR_5 | -26|5-pointed star (pentagram) |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_STAR_6 | -27|6-pointed star (hexagram) |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_STAR_7 | -28|7-pointed star (heptagram) |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_STAR_8 | -29|8-pointed star (octagram) |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_VLINE | -30|verical line |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_HLINE | -31|horizontal line |
+-----------------------------+-----+------------------------------------------------+
|MARKERTYPE_OMARK | -32|o-mark |
+-----------------------------+-----+------------------------------------------------+
Polymarkers appear centered over their specified coordinates.
"""
__gr.gr_setmarkertype(c_int(style))
def inqmarkertype():
mtype = c_int()
__gr.gr_inqmarkertype(byref(mtype))
return mtype.value
def setmarkersize(size):
"""
Specify the marker size for polymarkers.
**Parameters:**
`size` :
Scale factor applied to the nominal marker size
The polymarker size is calculated as the nominal size generated on the graphics device
multiplied by the marker size scale factor.
"""
__gr.gr_setmarkersize(c_double(size))
def setmarkercolorind(color):
"""
Define the color of subsequent polymarker output primitives.
**Parameters:**
`color` :
The polymarker color index (COLOR < 1256)
"""
__gr.gr_setmarkercolorind(c_int(color))
def inqmarkercolorind():
coli = c_int()
__gr.gr_inqmarkercolorind(byref(coli))
return coli.value
def settextfontprec(font, precision):
"""
Specify the text font and precision for subsequent text output primitives.
**Parameters:**
`font` :
Text font (see tables below)
`precision` :
Text precision (see table below)
The available text fonts are:
+--------------------------------------+-----+
|FONT_TIMES_ROMAN | 101|
+--------------------------------------+-----+
|FONT_TIMES_ITALIC | 102|
+--------------------------------------+-----+
|FONT_TIMES_BOLD | 103|
+--------------------------------------+-----+
|FONT_TIMES_BOLDITALIC | 104|
+--------------------------------------+-----+
|FONT_HELVETICA | 105|
+--------------------------------------+-----+
|FONT_HELVETICA_OBLIQUE | 106|
+--------------------------------------+-----+
|FONT_HELVETICA_BOLD | 107|
+--------------------------------------+-----+
|FONT_HELVETICA_BOLDOBLIQUE | 108|
+--------------------------------------+-----+
|FONT_COURIER | 109|
+--------------------------------------+-----+
|FONT_COURIER_OBLIQUE | 110|
+--------------------------------------+-----+
|FONT_COURIER_BOLD | 111|
+--------------------------------------+-----+
|FONT_COURIER_BOLDOBLIQUE | 112|
+--------------------------------------+-----+
|FONT_SYMBOL | 113|
+--------------------------------------+-----+
|FONT_BOOKMAN_LIGHT | 114|
+--------------------------------------+-----+
|FONT_BOOKMAN_LIGHTITALIC | 115|
+--------------------------------------+-----+
|FONT_BOOKMAN_DEMI | 116|
+--------------------------------------+-----+
|FONT_BOOKMAN_DEMIITALIC | 117|
+--------------------------------------+-----+
|FONT_NEWCENTURYSCHLBK_ROMAN | 118|
+--------------------------------------+-----+
|FONT_NEWCENTURYSCHLBK_ITALIC | 119|
+--------------------------------------+-----+
|FONT_NEWCENTURYSCHLBK_BOLD | 120|
+--------------------------------------+-----+
|FONT_NEWCENTURYSCHLBK_BOLDITALIC | 121|
+--------------------------------------+-----+
|FONT_AVANTGARDE_BOOK | 122|
+--------------------------------------+-----+
|FONT_AVANTGARDE_BOOKOBLIQUE | 123|
+--------------------------------------+-----+
|FONT_AVANTGARDE_DEMI | 124|
+--------------------------------------+-----+
|FONT_AVANTGARDE_DEMIOBLIQUE | 125|
+--------------------------------------+-----+
|FONT_PALATINO_ROMAN | 126|
+--------------------------------------+-----+
|FONT_PALATINO_ITALIC | 127|
+--------------------------------------+-----+
|FONT_PALATINO_BOLD | 128|
+--------------------------------------+-----+
|FONT_PALATINO_BOLDITALIC | 129|
+--------------------------------------+-----+
|FONT_ZAPFCHANCERY_MEDIUMITALIC | 130|
+--------------------------------------+-----+
|FONT_ZAPFDINGBATS | 131|
+--------------------------------------+-----+
The available text precisions are:
+---------------------------+---+--------------------------------------+
|TEXT_PRECISION_STRING | 0|String precision (higher quality) |
+---------------------------+---+--------------------------------------+
|TEXT_PRECISION_CHAR | 1|Character precision (medium quality) |
+---------------------------+---+--------------------------------------+
|TEXT_PRECISION_STROKE | 2|Stroke precision (lower quality) |
+---------------------------+---+--------------------------------------+
The appearance of a font depends on the text precision value specified.
STRING, CHARACTER or STROKE precision allows for a greater or lesser
realization of the text primitives, for efficiency. STRING is the default
precision for GR and produces the highest quality output.
"""
__gr.gr_settextfontprec(c_int(font), c_int(precision))
def setcharexpan(factor):
"""
Set the current character expansion factor (width to height ratio).
**Parameters:**
`factor` :
Text expansion factor applied to the nominal text width-to-height ratio
`setcharexpan` defines the width of subsequent text output primitives. The expansion
factor alters the width of the generated characters, but not their height. The default
text expansion factor is 1, or one times the normal width-to-height ratio of the text.
"""
__gr.gr_setcharexpan(c_double(factor))
def setcharspace(spacing):
__gr.gr_setcharspace(c_double(spacing))
def settextcolorind(color):
"""
Sets the current text color index.
**Parameters:**
`color` :
The text color index (COLOR < 1256)
`settextcolorind` defines the color of subsequent text output primitives.
GR uses the default foreground color (black=1) for the default text color index.
"""
__gr.gr_settextcolorind(c_int(color))
def setcharheight(height):
"""
Set the current character height.
**Parameters:**
`height` :
Text height value
`setcharheight` defines the height of subsequent text output primitives. Text height
is defined as a percentage of the default window. GR uses the default text height of
0.027 (2.7% of the height of the default window).
"""
__gr.gr_setcharheight(c_double(height))
def setcharup(ux, uy):
"""
Set the current character text angle up vector.
**Parameters:**
`ux`, `uy` :
Text up vector
`setcharup` defines the vertical rotation of subsequent text output primitives.
The text up vector is initially set to (0, 1), horizontal to the baseline.
"""
__gr.gr_setcharup(c_double(ux), c_double(uy))
def settextpath(path):
"""
Define the current direction in which subsequent text will be drawn.
**Parameters:**
`path` :
Text path (see table below)
+----------------------+---+---------------+
|TEXT_PATH_RIGHT | 0|left-to-right |
+----------------------+---+---------------+
|TEXT_PATH_LEFT | 1|right-to-left |
+----------------------+---+---------------+
|TEXT_PATH_UP | 2|downside-up |
+----------------------+---+---------------+
|TEXT_PATH_DOWN | 3|upside-down |
+----------------------+---+---------------+
"""
__gr.gr_settextpath(c_int(path))
def settextalign(horizontal, vertical):
"""
Set the current horizontal and vertical alignment for text.
**Parameters:**
`horizontal` :
Horizontal text alignment (see the table below)
`vertical` :
Vertical text alignment (see the table below)
`settextalign` specifies how the characters in a text primitive will be aligned
in horizontal and vertical space. The default text alignment indicates horizontal left
alignment and vertical baseline alignment.
+-------------------------+---+----------------+
|TEXT_HALIGN_NORMAL | 0| |
+-------------------------+---+----------------+
|TEXT_HALIGN_LEFT | 1|Left justify |
+-------------------------+---+----------------+
|TEXT_HALIGN_CENTER | 2|Center justify |
+-------------------------+---+----------------+
|TEXT_HALIGN_RIGHT | 3|Right justify |
+-------------------------+---+----------------+
+-------------------------+---+------------------------------------------------+
|TEXT_VALIGN_NORMAL | 0| |
+-------------------------+---+------------------------------------------------+
|TEXT_VALIGN_TOP | 1|Align with the top of the characters |
+-------------------------+---+------------------------------------------------+
|TEXT_VALIGN_CAP | 2|Aligned with the cap of the characters |
+-------------------------+---+------------------------------------------------+
|TEXT_VALIGN_HALF | 3|Aligned with the half line of the characters |
+-------------------------+---+------------------------------------------------+
|TEXT_VALIGN_BASE | 4|Aligned with the base line of the characters |
+-------------------------+---+------------------------------------------------+
|TEXT_VALIGN_BOTTOM | 5|Aligned with the bottom line of the characters |
+-------------------------+---+------------------------------------------------+
"""
__gr.gr_settextalign(c_int(horizontal), c_int(vertical))