-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsydPlotToolsV4.pro
1273 lines (1165 loc) · 39.5 KB
/
sydPlotToolsV4.pro
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
@'/home/ullrich/syd/sydTools.pro'
;+
;function in this file
;PageDef
;MakeCT
;RGB2Col
;ParamDef
;PlotDataDef
;GetLoc
;GetPos
;Loc2to4
;AutoClear
;FixLoc
;MakePlot
;BlockLabel
;FixContour
;MakeBox
;MakeLegend
;LevCol
;FixLength
;PlotMany
;
;New in V4
;Replaced makeHeaders system with blockLabel system
; instead of header space, page now has borders
; Page Structure conflicts with V3
;PixelPlot works how I like now
;Added ScreenPlot, allowing for realtime graphs
;made page into common block throughout calls
;added colbar function to replace weirdness of makelegend for both
;blocklabel uses pagewait
;-
;+
;CALL, PageDef,file,psize=psize,divs=divs,perDiv=perDiv,space=space,fsize=fsize
;file str File name to save as
;psize [x,y] Size of page {7.5,10}
;divs [x,y] Number of areas to split the page into
;perDiv [x,y] How many sub-areas per area
;space [num] Spacing around the page and between graphs {.75,.75,0,0} (last two are sub x&y)
; if given [x,y], sets main div spacing
; if given [-x,-y], sets subdiv spacing
;fsize # font size (72pt=1inch) {12}
;order [int] Natural order of graphs on page, {3,2,1,0 plots ysub first, then xsub, then y, then x)
;border [num] Margins of the page left,top,right,bottom {[space[0],space[1],space[0]/1.2,space[1]]}
;cct bool Custom Color Table?
;-
function PageDef,file,psize=psize,divs=divs,perDiv=perDiv,$
space=space,fsize=fsize,order=order,border=border,cct=cct,thick=thick
common comPage,page,pageLabel
if ~KEYWORD_SET(psize) then psize=[7.5,10]
if ~KEYWORD_SET(fsize) then fsize=12
if ~KEYWORD_SET(space) then space=[fsize/16.,fsize/16.,0.,0.] ;4.5 glyph heights
if N_ELEMENTS(space) eq 2 then begin
if space[0] ge 0 then space=[space,0,0] else space=[fsize/14.,fsize/14.,-space]
endif
if ~KEYWORD_SET(divs) then divs=[1,1]
if ~KEYWORD_SET(perDiv) then perDiv=[1,1]
if ~KEYWORD_SET(order) then order=[2,3,0,1]
if ~KEYWORD_SET(border) $
then border=FLOAT([space[0],space[1],space[0]/1.2,space[1]]) $
else if N_ELEMENTS(border) eq 1 then border=[1.,1.,1.,1.]
if ~ISA(thick) then thick=3
border[0]>=.5*fsize/12.
if ~ISA(cct) then loadct,39,/silent else begin
if ISA(cct,/int) then if cct eq 1 then MakeCT else loadct,cct
if ISA(cct,/str) then CALL_PROCEDURE,cct
endelse
SET_PLOT,'ps' ;plot is postscript
DEVICE,/portrait,$
xsize=psize[0],xoffset=border[0],$
ysize=psize[1],yoffset=border[1],$
font_size=fsize,/inches,/color,$
FILENAME=(STRMID(file,2,3,/reverse) ne '.ps')?file+'.ps':file ;ensure that file is valid postscript
;Get the font size in normalized units
XYOUTS,.5,.5,'W',WIDTH=w,CLIP=[0.,0.,0.1,0.1],COLOR=244,NOCLIP=0,FONT=-1,/NORMAL
!P.FONT=0
page={page,$
xsiz:psize[0],$
ysiz:psize[1],$
xdiv:divs[0]>1,$
ydiv:divs[1]>1,$
xsub:perDiv[0]>1,$
ysub:perDiv[1]>1,$
spc:float(space),$
fsiz:w,$
border:FLOAT(border),$
cur:-1,$
ord:order,$
thick:FLOAT(thick)}
pageLabel=[]
RETURN,page
END
PRO ClosePage
common ComPage,page,pagelabel
page=!null
pagelabel=!null
print,'closing page and deleting from common block'
if ~strcmp(!D.name,"X",/fold) then device,/close
END
;+
;Makes a screen plot
;CALL: ScreenPlot,cct=cct,fsize=fsize
;INPUTS:
;cct bool uses my colortable, or defaults to rainbow
;fsize num sets font size {14}
;-
PRO ScreenPlot,cct=cct,fsize=fsize,divs=divs,order=order
common comPage,page,pageLabel
if ~KEYWORD_SET(fsize) then fsize=14
if ~KEYWORD_SET(divs) then divs=[1,1]
if ~KEYWORD_SET(order) then order=[2,3,0,1]
SET_PLOT,'X' ;screen
DEVICE,DECOMPOSED=0,SET_CHARACTER_SIZE=fsize*[1,5./3],SET_FONT='Helvetica', /TT_FONT
if ~ISA(cct) then loadct,39,/silent else if cct eq 1 then MakeCT
!p.background = 255b & !p.color=0b;'ffffff'x & !p.color=0
XYOUTS,.5,.5,'W',WIDTH=w,CLIP=[0.,0.,0.1,0.1],COLOR=244,NOCLIP=0,/NORMAL
!P.FONT=0
page={page,$
xsiz:!d.X_SIZE,$
ysiz:!d.Y_SIZE,$
xdiv:divs[0]>1,$
ydiv:divs[1]>1,$
xsub:1,ysub:1,$
spc:[.75*fsize/14.,.75*fsize/14.,0.,0.]*!d.x_size/11.,$
fsiz:w,$
border:[80.,60.,80.,80.],$
cur:-1,$
ord:order,$
thick:1.}
ERASE
pageLabel=[]
END
PRO Clear
TVLCT,r,g,b,/get
v=SQRT(MAX(r^2.+g^2.+b^2.,ind))
POLYFILL,[0,0,1,1],[0,1,1,0],color=ind,/normal
END
;+
;Works much the same as !P.MULTI
;CALL: PageRediv,divs,subs=subs,cur=cur,spc=spc
;INPUTS:
;divs
;subs
;cur
;spc
;bor
;-
Pro PageRediv,divs,subs=subs,cur=cur,spc=spc,bor=bor
common comPage
if ISA(divs) then begin
page.xdiv=divs[0]
page.ydiv=divs[1]
endif
if KEYWORD_SET(subs) then begin
page.xsub=subs[0]
page.ysub=subs[1]
endif
if KEYWORD_SET(spc) then page.spc=spc
if KEYWORD_SET(bor) then page.border=bor
if ISA(cur) then page.cur=cur-1
if ~KEYWORD_SET(cur) then Autoclear,/force
END
;+
;Changes used page size (but not actual page)
;CALL: PageResiz,siz
;INPUTS:
;siz num new size in inches
;-
Pro PageResiz,siz,cur=cur
common comPage
if ISA(siz) then begin
page.xsiz=siz[0]
page.ysiz=siz[1]
endif
if KEYWORD_SET(cur) then page.cur=cur else begin
Autoclear,/force
page.cur-=1
endelse
END
;+
;Makes an RGB colortable
;Get colors from it with RGB2Col
;-
PRO MakeCT
opts=[6,7,6]
len=PRODUCT(opts)
cols=BYTARR([3,len])
rs=opts[1]*opts[2] & gs=opts[2] & bs=1
for r=0,0+len-rs,rs do begin
cols[0,r:r+rs-1]=FIX(255.*(r-0)/rs/(opts[0]-1))
for g=r,r+rs-gs,gs do begin
cols[1,g:g+gs-1]=FIX(255.*(g-r)/gs/(opts[1]-1))
for b=g,g+gs-bs do begin
cols[2,b:b+bs-1]=FIX(255.*(b-g)/bs/(opts[2]-1))
endfor
endfor
endfor
TVLCT,TRANSPOSE(cols)
END
PRO ColdHotCT,mag=mag,grn=grn
mag=255*KEYWORD_SET(mag)
grn=255*KEYWORD_SET(grn)
r = Interpol([ 0, 0, 0, 0,255,255,220,140,255], [0,1,25,75,127,180,230,254,255], FINDGEN(256))
g = Interpol([grn, 0, 0,255,255,255, 0, 0,mag], [0,1,25,90,127,165,230,254,255], FINDGEN(256))
b = Interpol([ 0,120,255,255,255, 0, 0, 0,255], [0,1,25,75,127,180,230,254,255], FINDGEN(256))
TVLCT, r, g, b
!p.background=127
END
PRO PaleCT
r = Interpol([0, 0, 40, 20, 0,100,255,255,255,180,255], [0,1,31,64,95,127,160,192,221,254,255], FINDGEN(256))
g = Interpol([0, 0, 40,160,255,255,255,165, 80, 0,255], [0,1,31,64,95,127,160,192,221,254,255], FINDGEN(256))
b = Interpol([0,180,255,255,255,120, 0, 0, 60, 0,255], [0,1,31,64,95,127,160,192,221,254,255], FINDGEN(256))
TVLCT, r, g, b
END
PRO ColorBlindCT
r=Interpol([ 0, 0, 0, 0,147,183,219,255],[0:7*38:38],FINDGEN(256))
g=Interpol([255,196,138, 78, 37,110, 83,255],[0:7*38:38],FINDGEN(256))
b=Interpol([255,255,255,255,219,146, 73, 0],[0:7*38:38],FINDGEN(256))
r[0]=0 & g[0]=0 & b[0]=0 & r[-1]=255 & g[-1]=255 & b[-1]=255
TVLCT, r, g, b
END
PRO TestCT,ct
page=PageDef('/home/ullrich/syd/plots/ColorTest.ps',psize=[7.5,10],cct=~ISA(ct),fsize=16)
if ISA(ct) then LoadCT,ct
mi=255
for i=0.,mi do begin
y=i/mi
POLYFILL,[0,1,1,0],[y,y,y+1./mi,y+1./mi],COLOR=i,/NORMAL
if (i mod 16) eq 0 then POLYFILL,[0,1,1,0],[y,y,y+.5/mi,y+.5/mi],COLOR=0,/NORMAL
endfor
for i=0.,mi,16. do XYOUTS,.1,i/mi,STRING(FORMAT='%i',i),/NORMAL
DEVICE,/close
END
;+
;Enter some rgb, get closest thing in color table
;-
FUNCTION RGB2Col,Rin,Gin,Bin
if N_PARAMS() eq 3 then ci=[[Rin],[Gin],[Bin]] else ci=Rin ;If not given three arguments assume the input was an array
if MAX(ci) le 1 then c=ci*251 else c=ci<252 ;Normalize as needed
if N_ELEMENTS(c[*,0]) ne 3 then c=TRANSPOSE(c) ;Maybe also turn the array, if needed
col=FIX(c[0,*]/42)*42 ;Get the red
col+=FIX(c[1,*]/36)*6 ;Get the green
col+=FIX(c[2,*])/42 ;Get the blue
col=REFORM(col)
if N_ELEMENTS(col) eq 1 then RETURN,col[0] else RETURN,col
END
;+
;Enter some rgb, get closest thing in color table
;-
FUNCTION Col2RGB,col
r=col/42
b=col mod 6
g=(col-r*42-b)/6.
RETURN,REFORM([r/5.,g/6.,b/5.],[N_ELEMENTS(col),3])
END
;+
;Enter some rgb, get closest thing in color table
;was used to create colortables like:
; colTBL=LONARR(256)
; for i=0,255 do COLTBL[i]=Rainbow24(255-i,v=(i/64.)<1)
; COLTBL[0:25]='ffffff'x
;-
FUNCTION Rainbow24,hue,v=v
if ~ISA(v) then v=1
hp=hue/42.5
X=(1-ABS(hp mod 2 -1))
if hp lt 1 or hp gt 5 then r=1 $
else if hp lt 3 then g=1 else b=1
if hp lt 2 then b=0 $
else if hp gt 4 then g=0 else r=0
if ~ISA(r) then r=x else if ~ISA(g) then g=x else b=x
col=FIX(255*v*[r,g,b])
mult=256L^[0,1,2]
RETURN,TOTAL(mult*col,/INT);256L*r+256L^2*g+256L^3*b-1
END
;+
;Plot parameters will allow us to come back to this plot
;-
Function ParamDef
RETURN,{PARAM,$
p:!P,$
x:!X,$
y:!Y,$
xr:[0.1,1.1],$
yr:[0.1,1.1],$
pos:[.1,.1,.1,.1],$
loc:[0,0,0,0]$
}
END
;+
;Establishes the general structure of plot data
;-
Function PlotDataDef
RETURN,{plotdata,$
name:'',$ ;This is the data's name
xd:PTR_NEW(),$ ;data x values
yd:PTR_NEW(),$ ;data y values
col:0} ;color to use in plots
END
;+
;Draw page labels made by BlockLabel
;-
PRO DrawPageLabels
common comPage,page,pageLabel
for i=0,N_ELEMENTS(pageLabel)-1 do begin
XYOUTS,pageLabel[i].xp,pageLabel[i].yp,pageLabel[i].labels,ALIGNMENT=.5,$
/NORMAL,ORIENTATION=pageLabel[i].r,CHARSIZE=pageLabel[i].sz
pageLabel[i].keep-=1
endfor
if ISA(PageLabel) then pagelabel=PageLabel[WHERE(pageLabel.keep gt 0,/NULL)]
end
;+
;Gets loc based on page.cur, makes a new page if the current one is full
;CALL: GetLoc
;RETURNS:
;loc [x,y,xsub,ysub] = where the graph should go
;-
Function GetLoc,noMove=noMove
common comPage
if ~KEYWORD_SET(noMove) then AutoClear
loc=[0.,0.,0.,0.]
bits=[page.xdiv,page.ydiv,page.xsub,page.ysub]
for i=0,3 do begin
a=WHERE(page.ord lt page.ord[i],cnt)
if cnt gt 0 then loc[i]=page.cur/FIX(PRODUCT(bits[a])) else loc[i]=page.cur
loc[i]=loc[i] mod bits[i]
endfor
RETURN,loc
END
;+
;Gets actual position on a page, based on location
;CALL: GetPos,loc=loc,units=units
;
;INPUTS:
;loc [num] Get one from GetLoc ([x,y,sub,ysub])
;units str Units of page (<'norm'>,'px' or 'pg')
;
;RETURNS:
;pos [xleast,yleast,xmost,ymost]
;-
Function GetPos,loc,units=units
common comPage
;Find Width and Height a main graph (in page units)
loc=FLOAT(loc)
w=(page.xsiz-(page.xdiv-1)*page.spc[0]-page.border[0]-page.border[2]-(page.xsub-1)*page.spc[2])/page.xdiv
h=(page.ysiz-(page.ydiv-1)*page.spc[1]-page.border[1]-page.border[3]-(page.ysub-1)*page.spc[3])/page.ydiv
pxl=page.border[0]+page.spc[0]*loc[0]+page.spc[2]*loc[2]+(loc[0]+loc[2]/page.xsub)*w
pxm=pxl+w/page.xsub
pym=page.ysiz-page.spc[1]*loc[1]-page.spc[3]*loc[3]-page.border[1]-(loc[1]+loc[3]/page.ysub)*h
pyl=pym-h/page.ysub
;Now in page units, might need to convert
rescale=[1,1]
if not KEYWORD_SET(units) then units='norm'
if units eq 'px' then rescale=[!D.X_SIZE,!D.Y_SIZE] ;this is pixels on the screen
if units ne 'pg' then rescale/=FLOAT([page.xsiz,page.ysiz]) ;this is normalization
RETURN, [[pxl,pyl]*rescale,[pxm,pym]*rescale]
END
;+
;Takes in 2 location arguments, figures
;CALL: Loc2to4,loc
;
;HOLDERS:
;Loc [num] ([x,y])
;-
Pro Loc2to4,loc
common comPage,page,pageLabel
if N_ELEMENTS(loc) ne 2 then PRINT,"Loc2to4 wants 2 elements in loc"
nl=INTARR(4)
nl[0]=loc[0]/page.xsub
nl[1]=loc[1]/page.ysub
nl[2]=loc[0] mod page.xsub
nl[3]=loc[1] mod page.ysub
loc=nl
END
;Force keyword makes a new page
;any time a page is about to be made, labels are drawn on the current page
PRO AutoClear,force=force
common comPage,page,pageLabel
page.cur+=1
if page.cur ge page.ydiv*page.xdiv*page.ysub*page.xsub or KEYWORD_SET(force) then begin
if ISA(pageLabel) then DrawPageLabels
page.cur=0
ERASE
endif
page.cur-=KEYWORD_SET(force)
END
Pro FixLoc,loc
common comPage,page,pageLabel
if loc[0] ge page.xdiv || loc[1] ge page.ydiv then begin
loc[0]-=page.xdiv*(loc[0] / page.xdiv)
loc[1]-=page.ydiv*(loc[1] / page.ydiv)
endif
END
;+
;My version of plot
;CALL: MakePlot(page,[Many options, see below])
;
;INPUTS:
;page page The page object that we draw on, get one from PageDef() (Deprecated)
;?d [num] x,y sample data, does not get plotted
;?r [num] x,y ranges
;er bool if set, expands x and y ranges to 0.9-1.1 times original
;?log bool x,y Sets an axis to be logaritmic
;units str Specifies to work in normal or data coordinates ('norm' or 'data') {'norm'}
;loc [num] Postion will be gotten from page divs ([x,y,xsub,ysub]) {GetLoc}
;pos [num] Position of plot ([xl,yl,xm,ym]) {GetPos(loc)}
;?title str x,y,_ Titles for the graph {'X','Y','Untitled'}
;calm bool if false, tries to automatically predict best title placement
;?style int x,y,line Styles, as normal {1,1,0}
; x&y bitwise 1 force exact, 2 extends axis, 4 surpresses, 8 only does left axis
;?Fake bool x,y Fakes an axis so that we have more control {False,False}
;?tval [num] x,y tick values, only used by fake axis, when ?Fake=1
;?num int x,y Number of major tick intervals
;?tint num x,y Interval between major ticks
;?tsub int x,y Subticks per tick
;?tlen flt x,y Major tick lengths
;?tlay int x,y Tick layout 0=normal, 1=labels only,2=?
;?tf int x,y Tick format
;?gstyle int x,y gridstyle
;norm bool Uses normal coords {!}
;iso bool Isotropic {0}
;label str If keyword is set, labels the plot. If str, uses itself as the label. {'a'}
;lcorn [str] corner to put the label in {['r','t']}
;noAxis bool Turn off the tick marks and tick labels
;auto bool Advance the plots, even if loc was given
;-
Function MakePlot,pageIn=pageIn,$
xd=xd,yd=yd,$;Data
xr=xr,yr=yr,er=er,$;Ranges
xlog=xlog,ylog=ylog,$;Log
units=units,loc=loc,pos=pos,$;Position
title=titleIn,xtitle=xtitleIn,ytitle=ytitleIn,$;Labels
calm=calm,$
linestyle=linestyle,xstyle=xstyle,ystyle=ystyle,$;Styles
xFake=xFake,yFake=yFake,$
xtval=xtval,ytval=ytval,$
xtnum=xtnum,ytnum=ytnum,$
xtint=xtint,ytint=ytint,$
xtsub=xtsub,ytsub=ytsub,$
xtlen=xtlen,ytlen=ytlen,$
xtlay=xtlay,ytlay=ytlay,$
xtf=xtf,ytf=ytf,$
xgstyle=xgstyle,ygstyle=ygstyle,$
norm=norm,iso=iso,$
label=label,lcorn=lcorn,noAxis=noAxis,auto=auto,_EXTRA=e
common comPage
if ISA(pageIn) then page=pageIn
if ~KEYWORD_SET(xd) then xd=[0.0,1.0]
if ~KEYWORD_SET(yd) then yd=[0.0,1.0]
if ~KEYWORD_SET(xr) then begin
xm=MAX(xd,min=xs)
xr=[xs,xm]
endif
if ~KEYWORD_SET(yr) then begin
ym=MAX(yd,min=ys)
yr=[ys,ym]
endif
if KEYWORD_SET(er) then begin
er=1.2
xr=((xr[1]+xr[0])+er*(xr[1]-xr[0])*[-1,1])/2.
yr=((yr[1]+yr[0])+er*(yr[1]-yr[0])*[-1,1])/2.
endif
if ~KEYWORD_SET(units) then units='norm'
if ~KEYWORD_SET(pos) then begin ;if pos provided, don't do any positioning
if ~KEYWORD_SET(loc) then loc=GetLoc() else $
if KEYWORD_SET(auto) then AutoClear
if N_ELEMENTS(loc) eq 2 then Loc2to4,loc ;x,y fill subdivs
FixLoc,loc
pos=GetPos(loc,units=units)
endif else loc=[0,0,0,0]
title=KEYWORD_SET(TitleIn)?titleIn:''
xtitle=KEYWORD_SET(xTitleIn)?xTitleIn:''
ytitle=KEYWORD_SET(yTitleIn)?yTitleIn:''
;Hide bits that are overlapping other graphs
if ~(KEYWORD_SET(calm) or KEYWORD_SET(noAxis) or (page.ysub eq 1)) then begin
XYOUTS,(pos[0]+pos[2])/2.,.9*pos[3]+.1*pos[1]-.3*page.fsiz,title,ALIGNMENT=.5,/NORMAL,CHARSIZE=1.4
title=''
endif
if loc[3] lt page.ysub-1 or keyword_set(noXAxis) then begin
xtnum=1;f='(A1)'
xtitle=''
endif
if loc[2] ne 0 or keyword_set(noYAxis) then begin
ytnum=1;f='(A1)'
ytitle=''
endif
if KEYWORD_SET(noAxis) then begin
xtf='(A1)'
ytf='(A1)'
xtitle=''
ytitle=''
xtlay=1
ytlay=1
endif
if ~ISA(xstyle) then xstyle=1
if ~ISA(ystyle) then ystyle=1
if KEYWORD_SET(xgstyle) and ~KEYWORD_SET(xtlen) then xtlen=.5
if KEYWORD_SET(ygstyle) and ~KEYWORD_SET(ytlen) then ytlen=.5
if KEYWORD_SET(xFake) then begin
xtitle2=TEMPORARY(xtitle)
xtf2=TEMPORARY(xtf)
xtf='(A1)'
xtlen2=TEMPORARY(xtlen) & xtlen=0.00001
xgstyle2=TEMPORARY(xgstyle)
endif
if KEYWORD_SET(yFake) then begin
ytitle2=TEMPORARY(ytitle)
ytf2=TEMPORARY(ytf)
ytf='(A1)'
ytlen2=TEMPORARY(ytlen) & ytlen=0.00001
ygstyle2=TEMPORARY(ygstyle)
endif
plot,xd,yd,$
XRANGE=xr,YRANGE=yr,$
XLOG=xlog,YLOG=ylog,$
XSTYLE=xstyle,YSTYLE=ystyle,$
TITLE=title,XTITLE=xtitle,YTITLE=ytitle,$
POSITION=pos,/NOERASE,/NODATA,$
NORMAL=norm,iso=iso,font=0,$
XTHICK=page.thick,YTHICK=page.thick,$
XTICKFORMAT=xtf,YTICKFORMAT=ytf,$
XTICKLEN=xtlen,YTICKLEN=ytlen,$
XTICKLAYOUT=xtlay,YTICKLAYOUT=ytlay,$
XTICKS=xtnum,YTICKS=ytnum,$
XTICKINTERVAL=xtint,YTICKINTERVAL=ytint,$
XMINOR=xtsub,YMINOR=ytsub,$
XGRIDSTYLE=xgstyle,YGRIDSTYLE=ygstyle,_EXTRA=e
if KEYWORD_SET(xFake) then begin
AXIS,0,yr[0],XAXIS=0,$
XRANGE=[xtval[0],xtval[-1]],$
XTITLE=xtitle2,$
XSTYLE=xstyle,$
XTICKLEN=xtlen2,$
XTICKS=N_ELEMENTS(xtval)-1,$
XTICKINTERVAL=xtint,$
XMINOR=xtsub,$
XTICKFORMAT=xtf2,$
XGRIDSTYLE=xgstyle2,$
XTHICK=page.thick
AXIS,0,yr[1],XAXIS=1,$
XRANGE=[xtval[0],xtval[-1]],$
XSTYLE=xstyle,$
XTICKLEN=(xtlen2 eq 1)?0.00001:xtlen2,$
XTICKS=N_ELEMENTS(xtval)-1,$
XTICKINTERVAL=xtint,$
XMINOR=xtsub,$
XTICKFORMAT='(A1)',$
XGRIDSTYLE=xgstyle2,$
XTHICK=page.thick
endif
if KEYWORD_SET(yFake) then begin
if ~KEYWORD_SET(ytsub) then ytsub=FIX((ytval[1]-ytval[0])^.5)
AXIS,xr[0],0,YAXIS=0,$
YRANGE=[ytval[0],ytval[-1]],$
YTITLE=Ytitle2,$
YSTYLE=ystyle,$
YTICKLEN=ytlen2,$
YTICKS=N_ELEMENTS(ytval)-1,$
YMINOR=ytsub,$
YTICKFORMAT=ytf2,$
YGRIDSTYLE=ygstyle2,$
YTHICK=page.thick
AXIS,xr[1],0,YAXIS=1,$
YRANGE=[ytval[0],ytval[-1]],$
YSTYLE=ystyle,$
YTICKLEN=(ytlen2 eq 1)?0.00001:ytlen2,$
YTICKS=N_ELEMENTS(ytval)-1,$
YMINOR=ytsub,$
YTICKFORMAT='(A1)',$
YGRIDSTYLE=ygstyle2,$
YTHICK=page.thick
endif
if ISA(label) then PlotLabel,label,pos,corner=lcorn ;Label Making
;Return acces to this graph
par={PARAM,p:!P,x:!X,y:!Y,xr:FLOAT(xr),yr:FLOAT(yr),pos:pos,loc:loc}
RETURN,par
END
;tl flt tick length
PRO MidAxis,plt,tl=tl
AXIS,0,0,xaxis=0,xrange=plt.xr,xticklen=tl,/xstyle
END
;+
;Mostly a helper function for MakePlot, can be called independently
;corner as stringarr ['r','t']
;-
PRO PlotLabel,label,pos,corner=corner,col=col,scl=scl
common comPage
if ~ISA(corner) then corner=['r','t']
if ~KEYWORD_SET(col) then col=0
if ~KEYWORD_SET(scl) then scl=2
xs=0 & ys=0
if TOTAL(STRCMP(corner,'r',1)) then xs=1 else if TOTAL(STRCMP(corner,'l',1)) then xs=-1
if TOTAL(STRCMP(corner,'t',1)) then ys=1 else if TOTAL(STRCMP(corner,'b',1)) then ys=-1
if ISA(label,/int) then begin
if label eq 1 then $
label=''+STRING(BYTE(97+page.cur))+'' else $
label=''+STRING(BYTE(97+page.cur+label))+''
endif
if ISA(label,/STRING) then begin
x=pos[1+xs]-xs*2.5/page.xdiv*page.fsiz
if TOTAL(STRCMP(corner,'x',1)) then x=(pos[0]+pos[2])/2
y=pos[2+ys]-(ys+.3)*3.*page.fsiz*page.xsiz/page.ysiz
XYOUTS,x,y,label,ALIGNMENT=.5+xs/4.,/NORMAL,CHARSIZE=scl,color=col,font=1
endif
END
;+
;Makes stuff good for pixelplot?
;this is sloppy
;-
PRO Pixelate,xd,yd,xr,yr,mx
MESSAGE,'what even uses this?'
n=50
xAxis=[xr[0]:xr[-1]:FLOAT(xr[-1]-xr[0])/n]
yAxis=[yr[0]:yr[-1]:FLOAT(yr[-1]-yr[0])/n]
CleanUp,xd,yd,nxd,nyd,zeros='remove'
dx=xaxis[1]-xaxis[0]
dy=yaxis[1]-yaxis[0]
h2d=hist_2d(nxd,nyd,bin1=dx,bin2=dy,$
min1=xr[0],max1=xr[-1],min2=yr[0],max2=yr[-1])
x=HISTOGRAM(nxd,min=0,max=6,nbins=n)
xi=[0,TOTAL(x,/cum)]
mx=MAX(x)
n_arr=FLTARR([n,n])
color=254./MAX(h2d)
for i=0,n-2 do begin
if x[i+1] gt 0 then hy=HISTOGRAM(nyd[xi[i]:xi[i+1]],min=0,max=6,NBINS=n) else hy=REPLICATE(0,n)
n_arr[i,*]=hy
for j=0,n-1 do PLOTS,xAxis[i]+.05,yAxis[j]+.05,col=hy[j]*color<254,psym=8,symsize=2
endfor
END
Pro PlotVecs,x,y,dx,dy,col=col
nx=N_ELEMENTS(x)
OPLOT,x,y,psym=4,symsize=.5
for i=0,nx-1 do OPLOT,x[i]+[0,dx[i]],y[i]+[0,dy[i]],col=col
END
Pro PlotPixels,z,x,y,sz,colp,acc=acc
if KEYWORD_SET(acc) then for i=MIN(colp,max=mi),mi do begin
q=WHERE(colp eq i)
PLOTS,x[q],y[q],col=i,psym=8
endfor else begin
sz=SIZE(z,/dim)
q=WHERE(FINITE(z),cnt)
PLOTS,x[q mod sz[0]],y[(q/sz[0]) mod sz[1]],col=colp[q],psym=8
endelse
END
Pro PlotEdges,z,x,y,sz,colp,edgeVert=edgeVert,thick=thick
if ~ISA(thick) then thick=2
sz[edgeVert+1]+=1;expand because plots needs n+1 points to make n segments
if edgeVert eq 1 then $
for i=0,sz[1]-1 do PLOTS,REPLICATE(x[i],sz[2]),y,color=[0,REFORM(colp[i,*])],thick=thick else $
for j=0,sz[2]-1 do PLOTS,x,REPLICATE(y[j],sz[1]),color=[0,colp[*,j]],thick=thick
END
Function FixBounds,z,x,y
xtp=WHERE(x ge !x.crange[0] and x lt !x.crange[1])
ytp=WHERE(y ge !y.crange[0] and y lt !y.crange[1])
z2=z[xtp,*]
z3=z2[*,ytp]
RETURN,z3
END
Function PixelRange,var,sz,crange,edgevert,edm
s=CRANGE[0] & m=CRANGE[1]-(CRANGE[1]-s)/sz
if ISA(edgevert) then if edgevert eq edm then m=CRANGE[1]
return,FLOAT([0:sz-1])/FLOAT(sz-1)*(m-s)+s
END
;+
;makeplot, but with colorful histograms
;An alternate to contour that gives continous depth buit discrete space
;
;INPUTS:
;z [num] data to plot
;x [int] x
;y [int] y
;leg bool make a legend here?
;sc num scale of pixels
;cols [int] colors
;levs [num] levels
;clipLev [num] truncate input data to these bounds
;bgc byte background color (uses current ct)
;allowColorWrap bool if values go outside specified levels, should we wrap or clip the colors
;noNorm bool if set, assign colors by interpolating from levs (False)
;edgeVert 0 for horizontal lines edges, 1 for vertical lines
;-
PRO PixelPlot,z,xi=xi,yi=yi,leg=leg,sc=sc,cols=cols,levs=levs,make=make,$
clipLev=clipLev,bgc=bgc,allowColorWrap=allowColorWrap,noNorm=noNorm,edgeVert=edgeVert
common comPage
sz=SIZE(z)
if keyword_set(make) then make=makeplot(xr=[0,sz[1]],yr=[0,sz[2]])
if ~KEYWORD_SET(xi) then x=PixelRange(xi,sz[1],!x.crange,edgevert,1) else x=xi
if (x[0] eq !x.crange[0] and x[-1] eq !x.crange[1]) then x=PixelRange(x,sz[1],!x.crange,edgevert,1)
if ~KEYWORD_SET(yi) then y=PixelRange(yi,sz[2],!y.crange,edgevert,0) else y=yi
if (y[0] eq !y.crange[0] and y[-1] eq !y.crange[1]) then y=PixelRange(y,sz[2],!y.crange,edgevert,0)
if ISA(edgevert) then begin
if edgeVert eq 0 then x=[x,2*x[-1]-x[-2]] else y=[y,2*y[-1]-y[-2]]
endif
if ~KEYWORD_SET(sc) then begin
pagePx=(!P.CLIP[2:3]-!P.CLIP[0:1])
sc=PagePx*2.05/!D.X_CH_SIZE/sz[1:2]
sc*=abs([(x[-1]-x[0])/(!x.CRANGE[1]-!X.crange[0]),(y[-1]-y[0])/(!y.CRANGE[1]-!y.crange[0])])
endif
USERSYM, [0,1,1,0,0]*sc[0],[0,0,1,1,0]*sc[1],/fill
;normalize data to color range
consider=WHERE(FINITE(z),cnt)
if cnt eq 0 then begin
PRINT,'No finite values'
RETURN
endif
s=MIN(z[consider],max=m)
m+=.01
if KEYWORD_SET(clipLev) then begin
if FINITE(clipLev[0]) then s=cliplev[0]
if FINITE(clipLev[1]) then m=cliplev[1]
endif else clipLev=[s,m]
if m eq s then nrm=z else nrm=255*(z-s)/(m-s)
if ~KEYWORD_SET(allowColorWrap) then nrm=(255<nrm>0) ;clips it to prevent wrap
colp=BYTE(nrm)
if ~KEYWORD_SET(levs) then levs=[s:m:(m-s)/12.]
if KEYWORD_SET(cols) or keyword_set(noNorm) then begin
colp*=0
if ~keyword_set(cols) then begin
if ~KEYWORD_SET(allowColorWrap) then z2u=min(levs,max=mx)>z<mx else z2u=z
colp=byte(interpol([0:255:255./(n_elements(levs)-1)],levs,z2u))
endif else for L=0,N_ELEMENTS(levs)-1 do begin
h=WHERE(z ge levs(L),cnt)
if cnt gt 0 then colp[h]=cols[L]
endfor
endif
if ISA(bgc) then MakeBox,[x[0],!x.crange[-1]],[y[0],!y.crange[-1]],col=bgc,units='data'
if ISA(edgeVert) then $
PlotEdges,z,x,y,sz,colp,edgeVert=edgeVert else $
PlotPixels,z,x,y,sz,colp
if ISA(leg) then begin
ml=MAX(ABS(levs))
form='%-4.1f'
if ml gt 10 then form='%3i'
if ml gt 100 then form='%4i'
if ml ge 1000 then form='%5i'
if KEYWORD_SET(leg) then ColBar,Levs,place=leg-[.0,0.5],form=form,posOut=leg
endif
END
;+
;Labels groups of plots (as produced by produced by MakePlot)
;CALL: BlockLabel,page,labels,size=size,xdivs=xdivs,ydivs=ydivs,$
; xsubs=xsubs,ysubs=ysubs,xLabel=xLabel,yLabel=yLabel
;
;INPUTS:
;labels [str] the labels to be written
;sizeL flt character size {1}
;?divs [int] x,y which major divisions to span
;?subs [int] x,y which minor divisions to span
;?Label bool x,y set to 0 to get top/left, set to 1 to get bottom/right
;now bool draw the labels right now {0} if not set, you should use DrawPageLabels
;pos [num] position of space around which to label, repllaces divs and subs
;keep [num] how many times to print a label before killing it
;-
PRO BlockLabel,labels,sizeL=sizeL,$
xdivs=xdivs,ydivs=ydivs,$
xsubs=xsubs,ysubs=ysubs,$
xLabel=xLabel,yLabel=yLabel,$
now=now,pos=pos,keep=keep
common comPage,page,pageLabel
if ~KEYWORD_SET(sizeL) then sizeL=1.0
if ~KEYWORD_SET(keep) then keep=1.0
nlabels=N_ELEMENTS(labels)
if ISA(xlabel) then begin
if (~ISA(xdivs) and ~ISA(xsubs)) then begin
xdivs=0 & xsubs=0
if nlabels eq page.xdiv $
then xdivs=[0:page.xdiv-1] $
else if nlabels eq page.xsub $
then xsubs=[0:page.xsub-1] $
else if nlabels eq page.xsub*page.xdiv then begin
xdivs=[0:page.xdiv-1]
xsubs=[0:page.xsub-1]
endif else xdivs=[0:nlabels-1]
endif
endif $
else if ISA(yLabel) then begin
if ~ISA(xdivs) then xdivs=[0:page.xdiv-1]
endif else MESSAGE,"You need to specify either x or y label"
if ~ISA(xsubs) then if ISA(xLabel) then xsubs=[0:page.xsub-1] else xsubs=0
if ~ISA(ydivs) then ydivs=0
if ~ISA(ysubs) then ysubs=0
nxd=N_ELEMENTS(xdivs) & nyd=N_ELEMENTS(ydivs)
nxs=N_ELEMENTS(xsubs) & nys=N_ELEMENTS(ysubs)
nx=nxd*nxs
ny=nyd*nys
if nx*ny ne nlabels then begin
if ((nx*ny mod nlabels) ne 0) then MESSAGE,"Number of blocks does not match number of labels"
newLabels=labels
while N_ELEMENTS(newLabels) lt nx*ny do newLabels=[newLabels,labels]
labels=newLabels
endif
for i=0,nx-1 do for j=0,ny-1 do begin ;Get the position of the block to be labelling
if KEYWORD_SET(pos) then begin
xs=pos[0] & ys=pos[1]
xm=pos[2] & ym=pos[3]
endif else begin
xm=0 & ym=0
xs=page.xsiz & ys=page.ysiz
if ISA(yLabel) then begin
if ylabel ne 0 and ylabel ne 1 then MESSAGE,"yLabel must be 0 or 1"
if ~KEYWORD_SET(ysubs) then begin
pos0=GetPos([xdivs[i],ydivs[j],0,0])
pos1=GetPos([xdivs[i],ydivs[j],page.xsub,page.ysub])
endif else begin
pos0=GetPos([xdivs[i],ydivs,0,ysubs[j]])
pos1=GetPos([xdivs[i],ydivs,page.xsub,ysubs[j]])
endelse
endif else if ISA(xLabel) then begin
if xlabel ne 0 and xlabel ne 1 then MESSAGE,"xLabel must be 0 or 1"
if ~KEYWORD_SET(xsubs) then begin
pos0=GetPos([xdivs[i],ydivs[j],0,0])
pos1=GetPos([xdivs[i],ydivs[j],page.xsub-1,page.ysub])
endif else begin
pos0=GetPos([xdivs,ydivs,xsubs[i],0])
pos1=GetPos([xdivs,ydivs,xsubs[i],page.ysub])
endelse
endif
xs=xs<pos0[0] & ym=ym>pos0[3]
xm=xm>pos1[2] & ys=ys<pos1[3]
endelse
if ISA(ylabel) then begin
xp=yLabel?xm+page.fsiz:xs-3.*page.fsiz ;right or left
yp=(ys+ym)/2 ;middle
endif else if ISA(xlabel) then begin
xp=(xs+xm)/2 ;middle
yp=xLabel?ys-3*page.fsiz:ym+page.fsiz*1.2 ;bottom or top
endif
pageLabel=[pageLabel,{label,$
xp:xp,yp:yp,labels:labels[i*ny+j],r:90*ISA(ylabel),sz:sizeL,keep:keep}]
endfor
if KEYWORD_SET(now) then DrawPageLabels
END
PRO BlockLabel2,label,sizeL=sizeL,$
divs=divs,subs=subs,$
xLabel=xLabel,yLabel=yLabel,$
now=now,keep=keep
common comPage,page,pageLabel
if ~KEYWORD_SET(sizeL) then sizeL=1.0
if ~KEYWORD_SET(keep) then keep=1.0
if ISA(xlabel) then begin
if KEYWORD_SET(divs) then subs=[0,page.xsub-1] else divs=0
pos0=getPos([divs[0],0,subs[0],0])
pos1=getPos([divs[-1],0,subs[-1],0])
endif
xs=pos0[0] & ym=pos0[3]
xm=pos1[2] & ys=pos1[3]
if ISA(ylabel) then begin
xp=yLabel?xm+page.fsiz:xs-3.*page.fsiz ;right or left
yp=(ys+ym)/2. ;middle
endif else if ISA(xlabel) then begin
xp=(xs+xm)/2. ;middle
yp=xLabel?ys-3*page.fsiz:ym+page.fsiz*1.2 ;bottom or top
endif
pageLabel=[pageLabel,{label,$
xp:xp,yp:yp,labels:label,r:90*ISA(ylabel),sz:sizeL,keep:keep}]
if KEYWORD_SET(now) then DrawPageLabels
END
PRO RedoAxis,par,xc,yc,xr=xr,yr=yr,xi,yi,xs=xs,ys=ys,thick=thick
common comPage
if ~KEYWORD_SET(thick) then thick=page.thick
if ~KEYWORD_SET(xr) then xr=par.xr
if ~KEYWORD_SET(yr) then yr=par.yr
;Draw the long ticks across the graph
AXIS,xr[0],0,YAXIS=0,YRANGE=yr,ystyle=1,yticklen=.5,ytickinterval=yi,color=yc,yminor=ys,ythick=thick,ytickformat='(A1)'
AXIS,xr[1],0,YAXIS=1,YRANGE=yr,ystyle=1,yticklen=.5,ytickinterval=yi,color=yc,yminor=ys,ythick=thick,ytickformat='(A1)'
AXIS,0,yr[0],XAXIS=0,XRANGE=xr,xstyle=1,xticklen=.5,xtickinterval=xi,color=xc,xminor=xs,xthick=thick,xtickformat='(A1)'
AXIS,0,yr[1],XAXIS=1,XRANGE=xr,xstyle=1,xticklen=.5,xtickinterval=xi,color=xc,xminor=xs,xthick=thick,xtickformat='(A1)'
END
;+
;Makes Axis fit for a contour plot
;CALL: FixContour,par,xc,yc,xi,yi,xs,ys
;par plot
;?c int colors of x and y tick marks
;?r [num] x,y range {from par}
;?i int x,y tick intervals
;?s int x,y sub-ticks intervals
;?title str x,y title {''}
;?tname [str] x,y tick labels {''}
;thick num thickness of axis to draw {4}
;-
PRO FixContour,par,xc,yc,xr=xr,yr=yr,xi,yi,xs,ys,thick=thick,$
xtitle=xtitle,ytitle=ytitle,xtname=xtname,ytname=ytname
;Draw the long ticks across the graph
RedoAXIS,par,xc,yc,xr=xr,yr=yr,xi,yi,xs=xs,ys=ys,thick=thick
;Do the labels
if N_ELEMENTS(xtname) eq 1 then $
if ISA(xtname,/STR) then $
xtname=REPLICATE(xtname,CEIL((!X.CRANGE[1]-!X.CRANGE[0])/FLOAT(xi)))
if N_ELEMENTS(ytname) eq 1 then $
if ISA(ytname,/STR) then $
ytname=REPLICATE(ytname,CEIL((!Y.CRANGE[1]-!Y.CRANGE[0])/FLOAT(yi)))
AXIS,0,yr[0],XAXIS=0,XRANGE=xr,xstyle=1,xticklayout=1,xtickinterval=xi,color=0,xminor=xs,xthick=thick,xtitle=xtitle,xtickname=xtname
AXIS,xr[0],0,YAXIS=0,YRANGE=yr,ystyle=1,yticklayout=1,ytickinterval=yi,color=0,yminor=ys,ythick=thick,ytitle=ytitle,ytickname=ytname
if xc ne 0 or yc ne 0 then $ ;makes the outline the right color
OPLOT,[xr[0],xr[1],xr[1],xr[0],xr[0]],[yr[0],yr[0],yr[1],yr[1],yr[0]],col=0,thick=thick
END
;+
;Draws a white box with black outline
;CALL: MakeBox,xr,yr,thick=thick,col=col,out=out,units=units
;xr,yr flt x and y ranges of the box to be made
;thick flt thickness of outline
;col int color
;units str 'norm' or 'data'
;-
PRO MakeBox,xr,yr,thick=thick,col=col,out=out,units=units
if ~KEYWORD_SET(units) then units='norm'
x1=MIN(xr,max=x2)
y1=MIN(yr,max=y2)
if N_ELEMENTS(col) eq 0 then col=!p.background;white as default
if ~ISA(thick) then thick=(x2-x1)/100