-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvis.py
More file actions
2641 lines (2304 loc) · 106 KB
/
vis.py
File metadata and controls
2641 lines (2304 loc) · 106 KB
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 -*-
"""
ovlib.vis: Visualization
===============================================================================
"""
# TODO: hide all these imports in the classes and methods
from cryspy.xtal import lattvec, miller, ipfgrid, fundzonePF, symm,\
unitcell, interpret_point_group_name
from cryspy.util import stereotrans, revstereotrans, revstereotransstandard, \
vecarraynorm, vecarraydot, vecarraycross, radians,\
rationalize, eatrans, reveatransstandard, reveatrans, \
polar, cart, vecarrayconvert, tic, toc
from cryspy.ebsd import triverts
import numpy as np
import numpy.linalg as npla
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.collections as mplcollections
import matplotlib.delaunay as mpltriang
#import visvis
import inspect
class stereoproj(object):
'''
stereoproj()
A stereographic projection represents the planes and the directions of a crystal.
A pole figure is a stereographic projection of the planes in the figure.
'''
def __init__(self, figure=None, subplot=None,
center=[0,0,1], south=[0,1,0], east=[1,0,0], **kwargs):
if not 'figsize' in kwargs:
kwargs['figsize'] = (8, 8)
# Open the figure
if figure:
self._figure = figure
else:
self._figure = plt.figure(**kwargs)
# Create first axis instance
if subplot:
self._ax = self._figure.add_subplot(subplot)
self._subplot = subplot
else:
self._ax = self._figure.add_subplot(111)
self._subplot = 111
# Create the background
plt.axes(self._ax).set_xbound(-1.05,1.05)
plt.axes(self._ax).set_ybound(-1.05,1.05)
circ=plt.Circle((0,0),1,facecolor='w',
edgecolor='k', linewidth=1, alpha=1, clip_on=False)
self._ax.add_patch(circ)
plt.axes(self._ax).set_aspect('equal')
plt.axes(self._ax).axison = False
south = vecarrayconvert(south)
east = vecarrayconvert(east)
center = vecarrayconvert(center)
if abs(vecarraydot(south,east))<np.sqrt(np.spacing(1)) and \
abs(vecarraydot(east,center))<np.sqrt(np.spacing(1)) and \
abs(vecarraydot(center,south))<np.sqrt(np.spacing(1)):
self._center=center
self._south=south
self._east=east
else:
print('The pole figure center, south, and east directions must be \
orthonormal. \
Proceeding with a standard projection')
self._center=[0,0,1]
self._south=[0,1,0]
self._east=[1,0,0]
if vecarraydot(vecarraycross(south,east),center)<np.sqrt(np.spacing(1)):
self._center=center
self._south=south
self._east=east
else:
print('The pole figure center, south, and east directions must \
form a right-handed system. \
Proceeding with a standard projection')
self._center=[0,0,1]
self._south=[0,1,0]
self._east=[1,0,0]
#-------------------------------------------------------------------------------
# Method for adding directions to the pole figure
def add_lattvec(self,v,uc,
# upper hemisphere options & defaults
upperlinewidth=None,
upperlinestyle='none',
uppercolor='r',
uppermarker='o',
uppermarkersize=None,
uppermarkeredgewidth=None,
uppermarkeredgecolor='r',
uppermarkerfacecolor='none',
uppermarkerfacecoloralt='none',
upperfillstyle='full',
upperdash_capstyle=None,
uppersolid_capstyle=None,
upperdash_joinstyle=None,
uppersolid_joinstyle=None,
# lower hemisphere options & defaults
lowerlinewidth=None,
lowerlinestyle='none',
lowercolor='none',
lowermarker='o',
lowermarkersize=None,
lowermarkeredgewidth=None,
lowermarkeredgecolor='r',
lowermarkerfacecolor='r',
lowermarkerfacecoloralt='none',
lowerfillstyle='full',
lowerdash_capstyle=None,
lowersolid_capstyle=None,
lowerdash_joinstyle=None,
lowersolid_joinstyle=None,
# plot options & defaults
pickradius=5,
drawstyle=None,
markevery=None,
antialiased=None,
**kwargs):
# assign relevant defaults from mpl.rcParams
if upperlinewidth is None :
upperlinewidth=mpl.rcParams['lines.linewidth']
if upperlinestyle is None :
upperlinestyle=mpl.rcParams['lines.linestyle']
if uppermarker is None :
uppermarker=mpl.rcParams['lines.marker']
if uppercolor is None :
uppercolor=mpl.rcParams['lines.color']
if uppermarkersize is None :
uppermarkersize=mpl.rcParams['lines.markersize']
if upperdash_capstyle is None :
upperdash_capstyle=mpl.rcParams['lines.dash_capstyle']
if upperdash_joinstyle is None :
upperdash_joinstyle=mpl.rcParams['lines.dash_joinstyle']
if uppersolid_capstyle is None :
uppersolid_capstyle=mpl.rcParams['lines.solid_capstyle']
if uppersolid_joinstyle is None :
uppersolid_joinstyle=mpl.rcParams['lines.solid_joinstyle']
if lowerlinewidth is None :
lowerlinewidth=mpl.rcParams['lines.linewidth']
if lowerlinestyle is None :
lowerlinestyle=mpl.rcParams['lines.linestyle']
if lowermarker is None :
lowermarker=mpl.rcParams['lines.marker']
if lowercolor is None :
lowercolor=mpl.rcParams['lines.color']
if lowermarkersize is None :
lowermarkersize=mpl.rcParams['lines.markersize']
if lowerdash_capstyle is None :
lowerdash_capstyle=mpl.rcParams['lines.dash_capstyle']
if lowerdash_joinstyle is None :
lowerdash_joinstyle=mpl.rcParams['lines.dash_joinstyle']
if lowersolid_capstyle is None :
lowersolid_capstyle=mpl.rcParams['lines.solid_capstyle']
if lowersolid_joinstyle is None :
lowersolid_joinstyle=mpl.rcParams['lines.solid_joinstyle']
if drawstyle is None :
drawstyle='default'
if antialiased is None :
antialiased=mpl.rcParams['lines.antialiased']
if isinstance(v,lattvec):
plt.subplot(self._subplot)
x,y,hem = stereotrans(v.to_cartesian(uc))
plt.plot(x[hem=='N'],y[hem=='N'],
linewidth=upperlinewidth,
linestyle=upperlinestyle,
color=uppercolor,
marker=uppermarker,
markersize=uppermarkersize,
markeredgewidth=uppermarkeredgewidth,
markeredgecolor=uppermarkeredgecolor,
markerfacecolor=uppermarkerfacecolor,
markerfacecoloralt=uppermarkerfacecoloralt,
fillstyle=upperfillstyle,
dash_capstyle=upperdash_capstyle,
solid_capstyle=uppersolid_capstyle,
dash_joinstyle=upperdash_joinstyle,
solid_joinstyle=uppersolid_joinstyle,
pickradius=pickradius,
drawstyle=drawstyle,
markevery=markevery,
antialiased=antialiased,
**kwargs)
plt.plot(x[hem=='S'],y[hem=='S'],
linewidth=lowerlinewidth,
linestyle=lowerlinestyle,
color=lowercolor,
marker=lowermarker,
markersize=lowermarkersize,
markeredgewidth=lowermarkeredgewidth,
markeredgecolor=lowermarkeredgecolor,
markerfacecolor=lowermarkerfacecolor,
markerfacecoloralt=lowermarkerfacecoloralt,
fillstyle=lowerfillstyle,
dash_capstyle=lowerdash_capstyle,
solid_capstyle=lowersolid_capstyle,
dash_joinstyle=lowerdash_joinstyle,
solid_joinstyle=lowersolid_joinstyle,
pickradius=pickradius,
drawstyle=drawstyle,
markevery=markevery,
antialiased=antialiased,
**kwargs)
plt.axes(self._ax).set_xbound(-1.05,1.05)
plt.axes(self._ax).set_ybound(-1.05,1.05)
#----------------------------------------------------------------------------
# Method for adding planes to the pole figure
def add_miller(self,v,uc,
# upper hemisphere options & defaults
upperlinewidth=None,
upperlinestyle='none',
uppercolor='b',
uppermarker='s',
uppermarkersize=None,
uppermarkeredgewidth=None,
uppermarkeredgecolor='b',
uppermarkerfacecolor='none',
uppermarkerfacecoloralt='none',
upperfillstyle='full',
upperdash_capstyle=None,
uppersolid_capstyle=None,
upperdash_joinstyle=None,
uppersolid_joinstyle=None,
# lower hemisphere options & defaults
lowerlinewidth=None,
lowerlinestyle='none',
lowercolor='none',
lowermarker='s',
lowermarkersize=None,
lowermarkeredgewidth=None,
lowermarkeredgecolor='b',
lowermarkerfacecolor='b',
lowermarkerfacecoloralt='none',
lowerfillstyle='full',
lowerdash_capstyle=None,
lowersolid_capstyle=None,
lowerdash_joinstyle=None,
lowersolid_joinstyle=None,
# plot options & defaults
pickradius=5,
drawstyle=None,
markevery=None,
antialiased=None,
**kwargs):
plt.subplot(self._subplot)
# assign relevant defaults from mpl.rcParams
if upperlinewidth is None :
upperlinewidth=mpl.rcParams['lines.linewidth']
if upperlinestyle is None :
upperlinestyle=mpl.rcParams['lines.linestyle']
if uppermarker is None :
uppermarker=mpl.rcParams['lines.marker']
if uppercolor is None :
uppercolor=mpl.rcParams['lines.color']
if uppermarkersize is None :
uppermarkersize=mpl.rcParams['lines.markersize']
if upperdash_capstyle is None :
upperdash_capstyle=mpl.rcParams['lines.dash_capstyle']
if upperdash_joinstyle is None :
upperdash_joinstyle=mpl.rcParams['lines.dash_joinstyle']
if uppersolid_capstyle is None :
uppersolid_capstyle=mpl.rcParams['lines.solid_capstyle']
if uppersolid_joinstyle is None :
uppersolid_joinstyle=mpl.rcParams['lines.solid_joinstyle']
if lowerlinewidth is None :
lowerlinewidth=mpl.rcParams['lines.linewidth']
if lowerlinestyle is None :
lowerlinestyle=mpl.rcParams['lines.linestyle']
if lowermarker is None :
lowermarker=mpl.rcParams['lines.marker']
if lowercolor is None :
lowercolor=mpl.rcParams['lines.color']
if lowermarkersize is None :
lowermarkersize=mpl.rcParams['lines.markersize']
if lowerdash_capstyle is None :
lowerdash_capstyle=mpl.rcParams['lines.dash_capstyle']
if lowerdash_joinstyle is None :
lowerdash_joinstyle=mpl.rcParams['lines.dash_joinstyle']
if lowersolid_capstyle is None :
lowersolid_capstyle=mpl.rcParams['lines.solid_capstyle']
if lowersolid_joinstyle is None :
lowersolid_joinstyle=mpl.rcParams['lines.solid_joinstyle']
if drawstyle is None :
drawstyle='default'
if antialiased is None :
antialiased=mpl.rcParams['lines.antialiased']
if isinstance(v,miller):
x,y,hem = stereotrans(v.to_cartesian(uc), center=self._center,
east=self._east, south=self._south)
plt.plot(x[hem=='N'],y[hem=='N'],
linewidth=upperlinewidth,
linestyle=upperlinestyle,
color=uppercolor,
marker=uppermarker,
markersize=uppermarkersize,
markeredgewidth=uppermarkeredgewidth,
markeredgecolor=uppermarkeredgecolor,
markerfacecolor=uppermarkerfacecolor,
markerfacecoloralt=uppermarkerfacecoloralt,
fillstyle=upperfillstyle,
dash_capstyle=upperdash_capstyle,
solid_capstyle=uppersolid_capstyle,
dash_joinstyle=upperdash_joinstyle,
solid_joinstyle=uppersolid_joinstyle,
pickradius=pickradius,
drawstyle=drawstyle,
markevery=markevery,
antialiased=antialiased,
**kwargs)
plt.plot(x[hem=='S'],y[hem=='S'],
linewidth=lowerlinewidth,
linestyle=lowerlinestyle,
color=lowercolor,
marker=lowermarker,
markersize=lowermarkersize,
markeredgewidth=lowermarkeredgewidth,
markeredgecolor=lowermarkeredgecolor,
markerfacecolor=lowermarkerfacecolor,
markerfacecoloralt=lowermarkerfacecoloralt,
fillstyle=lowerfillstyle,
dash_capstyle=lowerdash_capstyle,
solid_capstyle=lowersolid_capstyle,
dash_joinstyle=lowerdash_joinstyle,
solid_joinstyle=lowersolid_joinstyle,
pickradius=pickradius,
drawstyle=drawstyle,
markevery=markevery,
antialiased=antialiased,
**kwargs)
else:
print 'add_miller method for pole figures only accepts miller ' + \
'class input'
#----------------------------------------------------------------------------
def add_trace(self,v,uc,
resolution=25,
# upper hemisphere options & defaults
upperlinewidth=1,
upperlinestyle='-',
uppercolor='b',
uppermarker=None,
uppermarkersize=None,
uppermarkeredgewidth=None,
uppermarkeredgecolor='none',
uppermarkerfacecolor='none',
uppermarkerfacecoloralt='none',
upperfillstyle='full',
upperdash_capstyle=None,
uppersolid_capstyle=None,
upperdash_joinstyle=None,
uppersolid_joinstyle=None,
# lower hemisphere options & defaults
lowerlinewidth=1,
lowerlinestyle='--',
lowercolor='b',
lowermarker=None,
lowermarkersize=None,
lowermarkeredgewidth=None,
lowermarkeredgecolor='none',
lowermarkerfacecolor='none',
lowermarkerfacecoloralt='none',
lowerfillstyle='full',
lowerdash_capstyle=None,
lowersolid_capstyle=None,
lowerdash_joinstyle=None,
lowersolid_joinstyle=None,
# plot options & defaults
pickradius=5,
drawstyle=None,
markevery=None,
antialiased=None,
zorder=2,
**kwargs):
plt.subplot(self._subplot)
# assign relevant defaults from mpl.rcParams
if upperlinewidth is None :
upperlinewidth=mpl.rcParams['lines.linewidth']
if upperlinestyle is None :
upperlinestyle=mpl.rcParams['lines.linestyle']
if uppermarker is None :
uppermarker=mpl.rcParams['lines.marker']
if uppercolor is None :
uppercolor=mpl.rcParams['lines.color']
if uppermarkersize is None :
uppermarkersize=mpl.rcParams['lines.markersize']
if upperdash_capstyle is None :
upperdash_capstyle=mpl.rcParams['lines.dash_capstyle']
if upperdash_joinstyle is None :
upperdash_joinstyle=mpl.rcParams['lines.dash_joinstyle']
if uppersolid_capstyle is None :
uppersolid_capstyle=mpl.rcParams['lines.solid_capstyle']
if uppersolid_joinstyle is None :
uppersolid_joinstyle=mpl.rcParams['lines.solid_joinstyle']
if lowerlinewidth is None :
lowerlinewidth=mpl.rcParams['lines.linewidth']
if lowerlinestyle is None :
lowerlinestyle=mpl.rcParams['lines.linestyle']
if lowermarker is None :
lowermarker=mpl.rcParams['lines.marker']
if lowercolor is None :
lowercolor=mpl.rcParams['lines.color']
if lowermarkersize is None :
lowermarkersize=mpl.rcParams['lines.markersize']
if lowerdash_capstyle is None :
lowerdash_capstyle=mpl.rcParams['lines.dash_capstyle']
if lowerdash_joinstyle is None :
lowerdash_joinstyle=mpl.rcParams['lines.dash_joinstyle']
if lowersolid_capstyle is None :
lowersolid_capstyle=mpl.rcParams['lines.solid_capstyle']
if lowersolid_joinstyle is None :
lowersolid_joinstyle=mpl.rcParams['lines.solid_joinstyle']
if drawstyle is None :
drawstyle='default'
if antialiased is None :
antialiased=mpl.rcParams['lines.antialiased']
if isinstance(v,miller):
abc = vecarrayconvert(self._center)
nrmabc = 1.0/vecarraynorm(abc)
uvw = vecarrayconvert(self._east)
nrmuvw = 1.0/vecarraynorm(uvw)
fed = vecarrayconvert(self._south) # 'def' is reserved in python
nrmdef = 1.0/vecarraynorm(fed)
xyz = v.to_cartesian(uc)
nrmxyz = 1.0/vecarraynorm(xyz)
xx = xyz[0]*nrmxyz
yy = xyz[1]*nrmxyz
zz = xyz[2]*nrmxyz
n = np.shape(xx)
aa = np.tile(abc[0]*nrmabc,n)
bb = np.tile(abc[1]*nrmabc,n)
cc = np.tile(abc[2]*nrmabc,n)
dd = np.tile(fed[0]*nrmdef,n)
ee = np.tile(fed[1]*nrmdef,n)
ff = np.tile(fed[2]*nrmdef,n)
uu = np.tile(uvw[0]*nrmuvw,n)
vv = np.tile(uvw[1]*nrmuvw,n)
ww = np.tile(uvw[2]*nrmuvw,n)
cosdl = vecarraydot([xx,yy,zz],[dd,ee,ff])
cosmu = vecarraydot([xx,yy,zz],[uu,vv,ww])
cosal = vecarraydot([xx,yy,zz],[aa,bb,cc])
denom = 1.0/(1.0+abs(cosal))
xproj = cosmu * denom
yproj = cosdl * denom
hemis = np.tile('N',n)
if np.array(n)>1:
hemis[cosal<0.0] = 'S'
else:
if cosal<0.0:
hemis = np.tile('S',n)
denom = np.sqrt(xproj*xproj+yproj*yproj)
denom[denom==0.0]=1.0
cosrho = xproj/denom
sinrho = yproj/denom
cosrho[denom==0.0]=0.0
sinrho[denom==0.0]=0.0
alpha = np.arccos(cosal)
i=-1
for almx in alpha:
# 1/cos and tan have problems near pi/2
if (abs(almx)-np.pi/2.0)<np.sqrt(np.spacing(1)):
almx=abs(almx)-np.sqrt(np.spacing(1))
rgc = 1.0/np.cos(almx)
ogc = np.tan(almx)
thi = np.pi/2.0+almx
thf = 3.0*np.pi/2.0-almx
ths = (thf-thi)/resolution
th = np.arange(thi,thf+ths/2.0,ths)
x = rgc*np.cos(th)+ogc
y = rgc*np.sin(th)
i=i+1
cr = cosrho[i]
sr = sinrho[i]
if hemis[i]=='N':
plt.plot(x*cr-y*sr,y*cr+x*sr,
linewidth=upperlinewidth,
linestyle=upperlinestyle,
color=uppercolor,
marker=uppermarker,
markersize=uppermarkersize,
markeredgewidth=uppermarkeredgewidth,
markeredgecolor=uppermarkeredgecolor,
markerfacecolor=uppermarkerfacecolor,
markerfacecoloralt=uppermarkerfacecoloralt,
fillstyle=upperfillstyle,
dash_capstyle=upperdash_capstyle,
solid_capstyle=uppersolid_capstyle,
dash_joinstyle=upperdash_joinstyle,
solid_joinstyle=uppersolid_joinstyle,
pickradius=pickradius,
drawstyle=drawstyle,
markevery=markevery,
antialiased=antialiased,
zorder=zorder,
**kwargs)
if hemis[i]=='S':
plt.plot(-x*cr+y*sr,-y*cr-x*sr,
linewidth=lowerlinewidth,
linestyle=lowerlinestyle,
color=lowercolor,
marker=lowermarker,
markersize=lowermarkersize,
markeredgewidth=lowermarkeredgewidth,
markeredgecolor=lowermarkeredgecolor,
markerfacecolor=lowermarkerfacecolor,
markerfacecoloralt=lowermarkerfacecoloralt,
fillstyle=lowerfillstyle,
dash_capstyle=lowerdash_capstyle,
solid_capstyle=lowersolid_capstyle,
dash_joinstyle=lowerdash_joinstyle,
solid_joinstyle=lowersolid_joinstyle,
pickradius=pickradius,
drawstyle=drawstyle,
markevery=markevery,
antialiased=antialiased,
zorder=zorder,
**kwargs)
#----------------------------------------------------------------------------
def grid_spokes(self,degreestep=90.0,mindegrees=0.0,maxdegrees=360.0,
resolution=25,
poleclip=0,
rotation=0.0,
linewidth=1,
linestyle='-',
color=[0.6,0.6,0.6],
marker=None,
markersize=None,
markeredgewidth='none',
markeredgecolor='none',
markerfacecolor='none',
markerfacecoloralt='none',
fillstyle='full',
dash_capstyle=None,
solid_capstyle=None,
dash_joinstyle=None,
solid_joinstyle=None,
pickradius=None,
drawstyle=None,
markevery=None,
antialiased=None,
zorder=1,
**kwargs):
plt.subplot(self._subplot)
# assign relevant defaults from mpl.rcParams
if linewidth is None :
linewidth=mpl.rcParams['lines.linewidth']
if linestyle is None :
linestyle=mpl.rcParams['lines.linestyle']
if marker is None :
marker=mpl.rcParams['lines.marker']
if color is None :
color=mpl.rcParams['lines.color']
if markersize is None :
markersize=mpl.rcParams['lines.markersize']
if dash_capstyle is None :
dash_capstyle=mpl.rcParams['lines.dash_capstyle']
if dash_joinstyle is None :
dash_joinstyle=mpl.rcParams['lines.dash_joinstyle']
if solid_capstyle is None :
solid_capstyle=mpl.rcParams['lines.solid_capstyle']
if solid_joinstyle is None :
solid_joinstyle=mpl.rcParams['lines.solid_joinstyle']
if drawstyle is None :
drawstyle='default'
if antialiased is None :
antialiased=mpl.rcParams['lines.antialiased']
poleclip=radians(poleclip)
th = np.arange(mindegrees,maxdegrees+degreestep,degreestep)
th = th * np.pi / 180.0
lin = np.arange(poleclip,1.0+0.5/resolution,1.0/resolution)
rho = radians(rotation)
cosrho = np.cos(rho)
sinrho = np.sin(rho)
for alph in th:
x = lin * np.cos(alph)
y = lin * np.sin(alph)
plt.plot(x*cosrho-y*sinrho,y*cosrho+x*sinrho,
linewidth=linewidth,
linestyle=linestyle,
color=color,
marker=marker,
markersize=markersize,
markeredgewidth=markeredgewidth,
markeredgecolor=markeredgecolor,
markerfacecolor=markerfacecolor,
markerfacecoloralt=markerfacecoloralt,
fillstyle=fillstyle,
dash_capstyle=dash_capstyle,
solid_capstyle=solid_capstyle,
dash_joinstyle=dash_joinstyle,
solid_joinstyle=solid_joinstyle,
pickradius=pickradius,
drawstyle=drawstyle,
markevery=markevery,
antialiased=antialiased,
zorder=zorder,
**kwargs)
plt.axes(plt.gca()).set_xbound(-1.05,1.05)
plt.axes(plt.gca()).set_ybound(-1.05,1.05)
#----------------------------------------------------------------------------
def grid_greatcircles(self,degreestep=45.0,
mindegrees=0.0,maxdegrees=180,
resolution=25,
linewidth=1,
linestyle='-',
color=[0.6,0.6,0.6],
poleclip=0.0,
rotation=0.0,
marker=None,
markersize=None,
markeredgewidth='none',
markeredgecolor='none',
markerfacecolor='none',
markerfacecoloralt='none',
fillstyle='full',
dash_capstyle=None,
solid_capstyle=None,
dash_joinstyle=None,
solid_joinstyle=None,
pickradius=None,
drawstyle=None,
markevery=None,
antialiased=None,
zorder=1,
**kwargs):
plt.subplot(self._subplot)
# assign relevant defaults from mpl.rcParams
if linewidth is None :
linewidth=mpl.rcParams['lines.linewidth']
if linestyle is None :
linestyle=mpl.rcParams['lines.linestyle']
if marker is None :
marker=mpl.rcParams['lines.marker']
if color is None :
color=mpl.rcParams['lines.color']
if markersize is None :
markersize=mpl.rcParams['lines.markersize']
if dash_capstyle is None :
dash_capstyle=mpl.rcParams['lines.dash_capstyle']
if dash_joinstyle is None :
dash_joinstyle=mpl.rcParams['lines.dash_joinstyle']
if solid_capstyle is None :
solid_capstyle=mpl.rcParams['lines.solid_capstyle']
if solid_joinstyle is None :
solid_joinstyle=mpl.rcParams['lines.solid_joinstyle']
if drawstyle is None :
drawstyle='default'
if antialiased is None :
antialiased=mpl.rcParams['lines.antialiased']
# Create the alpha range
alpha = np.arange(mindegrees,maxdegrees+degreestep,degreestep)
if any(alpha>180.0) or any(alpha<0.0):
print 'valid range for grid_verticalgreatcircles \
is between 0 and 180'
# Put data in our valid range
alpha = alpha * np.pi/180.0
alpha = alpha[alpha>0.0]
alpha = alpha[alpha<np.pi]
alpha = alpha[alpha!=np.pi/2.0]
poleclip = np.pi/2.0-radians(poleclip)+np.spacing(1)
rho = radians(rotation)
cosrho = np.cos(rho)
sinrho = np.sin(rho)
# clip near the poles using the geometry of
# the small circle and the chord formula
rsc = 1.0/np.tan(poleclip)
osc = 1.0/np.sin(poleclip)
for almx in alpha:
if almx<np.pi/2:
rgc = 1.0/np.cos(almx)
ogc = np.tan(almx)
d2 = osc * osc + ogc * ogc
kk = 0.25 * np.sqrt((( rsc + rgc)**2.0 - d2) \
* (d2 - (rgc - rsc)**2.0 ))
x2 = 0.5*ogc - 0.5*ogc*(rgc*rgc - rsc*rsc)/d2 - 2.0*osc*kk/d2
y2 = 0.5*osc + 0.5*osc*(rgc*rgc - rsc*rsc)/d2 - 2.0*ogc*kk/d2
v1 = np.array([-ogc, 1.0])
v1 = v1 / npla.norm(v1)
v2 = np.array([x2 - ogc, y2])
v2 = v2 / npla.norm(v2)
pc = np.arccos(np.dot(v1, v2))
thi = np.pi/2.0+almx+pc
thf = 3.0*np.pi/2.0-almx-pc
ths = (thf-thi)/resolution
th = np.arange(thi,thf+0.5*ths,ths)
x = rgc*np.cos(th)+ogc
y = rgc*np.sin(th)
rho=radians(25.0)
plt.plot(x*cosrho-y*sinrho,y*cosrho+x*sinrho,
linewidth=linewidth,
linestyle=linestyle,
color=color,
marker=marker,
markersize=markersize,
markeredgewidth=markeredgewidth,
markeredgecolor=markeredgecolor,
markerfacecolor=markerfacecolor,
markerfacecoloralt=markerfacecoloralt,
fillstyle=fillstyle,
dash_capstyle=dash_capstyle,
solid_capstyle=solid_capstyle,
dash_joinstyle=dash_joinstyle,
solid_joinstyle=solid_joinstyle,
pickradius=pickradius,
drawstyle=drawstyle,
markevery=markevery,
antialiased=antialiased,
zorder=zorder, #place b/t grid & background
**kwargs)
if almx>=np.pi/2:
rgc = 1.0/np.cos(almx)
ogc = np.tan(almx)
d2 = osc * osc + ogc * ogc
kk = 0.25 * np.sqrt((( rsc + rgc)**2.0 - d2) \
* (d2 - (rgc - rsc)**2.0 ))
x2 = 0.5*ogc-0.5*ogc*(rgc*rgc - rsc*rsc)/d2 + 2.0*osc*kk/d2
y2 = 0.5*osc+0.5*osc*(rgc*rgc - rsc*rsc)/d2 + 2.0*ogc*kk/d2
v1=np.array([-ogc,1.0])
v1=v1/npla.norm(v1)
v2=np.array([x2-ogc,y2])
v2=v2/npla.norm(v2)
pc=np.arccos(np.dot(v1, v2))
thi=3.0*np.pi/2.0-almx+pc
thf=np.pi/2.0+almx-pc
ths=(thf-thi)/resolution
th = np.arange(thi,thf+0.5*ths,ths)
x = rgc*np.cos(th)+ogc
y = rgc*np.sin(th)
plt.plot(x*cosrho-y*sinrho,y*cosrho+x*sinrho,
linewidth=linewidth,
linestyle=linestyle,
color=color,
marker=marker,
markersize=markersize,
markeredgewidth=markeredgewidth,
markeredgecolor=markeredgecolor,
markerfacecolor=markerfacecolor,
markerfacecoloralt=markerfacecoloralt,
fillstyle=fillstyle,
dash_capstyle=dash_capstyle,
solid_capstyle=solid_capstyle,
dash_joinstyle=dash_joinstyle,
solid_joinstyle=solid_joinstyle,
pickradius=pickradius,
drawstyle=drawstyle,
markevery=markevery,
antialiased=antialiased,
zorder=zorder,
**kwargs)
plt.axes(plt.gca()).set_xbound(-1.05,1.05)
plt.axes(plt.gca()).set_ybound(-1.05,1.05)
#----------------------------------------------------------------------------
def grid_smallcircles(self,degreestep=45.0,
mindegrees=0.0,maxdegrees=180,
resolution=25,
rotation=0.0,
linewidth=1,
linestyle='-',
color=[0.6,0.6,0.6],
marker=None,
markersize=None,
markeredgewidth='none',
markeredgecolor='none',
markerfacecolor='none',
markerfacecoloralt='none',
fillstyle='full',
dash_capstyle=None,
solid_capstyle=None,
dash_joinstyle=None,
solid_joinstyle=None,
pickradius=None,
drawstyle=None,
markevery=None,
antialiased=None,
zorder=1,
**kwargs):
plt.subplot(self._subplot)
# assign relevant defaults from mpl.rcParams
if linewidth is None :
linewidth=mpl.rcParams['lines.linewidth']
if linestyle is None :
linestyle=mpl.rcParams['lines.linestyle']
if marker is None :
marker=mpl.rcParams['lines.marker']
if color is None :
color=mpl.rcParams['lines.color']
if markersize is None :
markersize=mpl.rcParams['lines.markersize']
if dash_capstyle is None :
dash_capstyle=mpl.rcParams['lines.dash_capstyle']
if dash_joinstyle is None :
dash_joinstyle=mpl.rcParams['lines.dash_joinstyle']
if solid_capstyle is None :
solid_capstyle=mpl.rcParams['lines.solid_capstyle']
if solid_joinstyle is None :
solid_joinstyle=mpl.rcParams['lines.solid_joinstyle']
if drawstyle is None :
drawstyle='default'
if antialiased is None :
antialiased=mpl.rcParams['lines.antialiased']
# Create the alpha range
beta = np.arange(mindegrees,maxdegrees+degreestep,degreestep)
if any(beta>180.0) or any(beta<0.0):
print 'valid range for grid_verticalgreatcircles \
is between 0 and 180'
# Put data in our valid range
beta = beta * np.pi/180.0
beta = beta[beta>0.0]
beta = beta[beta<np.pi]
beta = beta[beta!=np.pi/2.0]
rho = radians(rotation)
cosrho = np.cos(rho)
sinrho = np.sin(rho)
for bemx in beta:
if bemx<np.pi/2.0:
rsc = 1.0/np.tan(bemx)
org = 1.0/np.sin(bemx)
thi = np.pi/2.0-bemx
thf = np.pi/2.0+bemx
ths = (thf-thi)/resolution
th = np.arange(thi,thf+0.5*ths,ths)
x = rsc*np.cos(th)
y = rsc*np.sin(th)-org
plt.plot(x*cosrho-y*sinrho,y*cosrho+x*sinrho,
linewidth=linewidth,
linestyle=linestyle,
color=color,
marker=marker,
markersize=markersize,
markeredgewidth=markeredgewidth,
markeredgecolor=markeredgecolor,
markerfacecolor=markerfacecolor,
markerfacecoloralt=markerfacecoloralt,
fillstyle=fillstyle,
dash_capstyle=dash_capstyle,
solid_capstyle=solid_capstyle,
dash_joinstyle=dash_joinstyle,
solid_joinstyle=solid_joinstyle,
pickradius=pickradius,
drawstyle=drawstyle,
markevery=markevery,
antialiased=antialiased,
zorder=zorder,# place grid b/t data and background
**kwargs)
if bemx>=np.pi/2:
rsc = 1.0/np.tan(bemx)
org = 1.0/np.sin(bemx)
thi = bemx-np.pi/2.0
thf = 3.0*np.pi/2.0-bemx
ths = (thf-thi)/resolution
th = -np.arange(thi,thf+0.5*ths,ths)
x = rsc*np.cos(th)
y = -rsc*np.sin(th)+org
plt.plot(x*cosrho-y*sinrho,y*cosrho+x*sinrho,
linewidth=linewidth,
linestyle=linestyle,
color=color,
marker=marker,
markersize=markersize,
markeredgewidth=markeredgewidth,
markeredgecolor=markeredgecolor,
markerfacecolor=markerfacecolor,
markerfacecoloralt=markerfacecoloralt,
fillstyle=fillstyle,
dash_capstyle=dash_capstyle,
solid_capstyle=solid_capstyle,
dash_joinstyle=dash_joinstyle,
solid_joinstyle=solid_joinstyle,
pickradius=pickradius,
drawstyle=drawstyle,
markevery=markevery,
antialiased=antialiased,
zorder=zorder,
**kwargs)
plt.axes(plt.gca()).set_xbound(-1.05,1.05)
plt.axes(plt.gca()).set_ybound(-1.05,1.05)
#----------------------------------------------------------------------------
def grid_rings(self,degreestep=45.0,
mindegrees=0.0,maxdegrees=90.0,
resolution=25,
linewidth=1,
linestyle='-',
color=[0.6,0.6,0.6],
marker=None,
markersize=None,