-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotOutput.py
More file actions
2545 lines (2399 loc) · 111 KB
/
Copy pathplotOutput.py
File metadata and controls
2545 lines (2399 loc) · 111 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
from multiprocessing import Pool
import getGraphProps as gGP
import matplotlib.ticker as ticker
from matplotlib.ticker import FuncFormatter, FormatStrFormatter
import numpy as np
import os
import util_fns as uf
#import matplotlib
#matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib as mpl
from pca import pca
import pygraphviz as pgv
# pgv.Draw
# from mpltools import style
# from mpltools import layout
# style.use('ggplot')
# global variables to the (hopefully temporary) rescue of aligning colornorms
# PLEASE DELETE ASAP
def gamma_bullshit():
"""gamma function investigatoin"""
f = lambda x, k: np.power(x, k-1)*np.exp(-x)/scipy.special.gamma(k)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.linspace(0, 120, 100), f(np.linspace(0, 120, 100), 10))
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.linspace(0, 120, 100), f(np.linspace(0, 120, 100), 20))
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.linspace(0, 120, 100), f(np.linspace(0, 120, 100), 100))
plt.show()
def thin_array(array, frac_to_keep=0.5, new_npts=None):
#
# !!! shape of array must be (x, y), cannot be (x,) !!!
#
# will keep 100*frac_to_keep% of the data
# in each column of array, evenly spaced
# thus, array has form col1 col2 col3 .. colN
# and returns col1 col2...colN reduced to frac_to_keep of
# original length
# no thinning is possible for frac_to_keep > 0.5,
# at least in this arrangement
if new_npts is None:
if frac_to_keep > 0.5:
return array
else:
npts = array.shape[0]
new_npts = int(frac_to_keep*npts)
spacing = npts/new_npts
ncols = array.shape[1]
thinned_array = np.zeros((new_npts, ncols))
else:
npts = array.shape[0]
if new_npts > npts/2:
return array
else:
spacing = npts/new_npts
ncols = array.shape[1]
thinned_array = np.zeros((new_npts, ncols))
for i in range(new_npts):
thinned_array[i,:] = array[spacing*i, :]
return thinned_array
def get_data(filename, header_rows=1, **kwargs):
path_to_file = os.path.realpath(filename)
f = open(path_to_file, "r")
params_str = f.readline()
params = get_header_data(params_str)
f.close()
data = np.genfromtxt(path_to_file, delimiter=",", skip_header=header_rows, **kwargs)
print 'done importing data from', filename
return data, params
def get_header_data(header_str):
BEGIN = 0
comma = 1
#create dict from header, based on key=value format in csv
params = {}
while comma > 0:
equals = header_str.find("=")
comma = header_str.find(",")
params[header_str[BEGIN:equals]] = float(header_str[equals+1:comma])
header_str = header_str[comma+1:]
params[header_str[BEGIN:equals]] = float(header_str[equals+1:comma])
#make integer, may not work especially well
for key in params:
if(params[key] % 1 == 0):
params[key] = int(params[key])
return params
def genData(fileName):
pathToFile = os.path.realpath(fileName)
f = open(pathToFile, "r")
paramstr = f.readline()
params = {}
f.close()
begin = 0
comma = 1
#create dict from header, based on key=value format in csv
while comma > 0:
comma = paramstr.find(",")
equals = paramstr.find("=")
params[paramstr[begin:equals]] = float(paramstr[equals+1:comma])
paramstr = paramstr[comma+1:]
params[paramstr[begin:equals]] = float(paramstr[equals+1:comma])
for key in params:
if(params[key] % 1 == 0):
params[key] = int(params[key])
data = np.genfromtxt(pathToFile, delimiter=",", skip_header=1)
print params
return params, data
def makeFolder(baseName):
folderCount = 0
newFolder = baseName + str(folderCount) + '/'
while os.path.exists(newFolder):
folderCount = folderCount + 1
newFolder = baseName + str(folderCount) + '/'
os.mkdir(newFolder)
return newFolder
def genFileName(baseName, params, uniqueID=''):
fileName = baseName
for key in params.keys():
fileName = fileName + '_' + key + '_' + str(params[key])
return fileName + '_' + uniqueID
def animateContour(data, params, cmap='Paired', fps=10, bitrate=14400, containerType='.mkv'):
import matplotlib.animation as animation
nData = params['nSteps']/params['dataInterval']
n = params['n']
fig = plt.figure(facecolor='w')
plt.text(n/2,1.05*params['n'],'Evolution of adjacency matrix in preferential attachment model', ha='center', fontsize=16)
newFolder = makeFolder('contourPlots')
for i in range(nData):
plt.clf()
plt.pcolormesh(data[(i)*n:(i+1)*n,:n], cmap=cmap)
plt.draw()
fileName = genFileName('contour', params, str(i))
plt.savefig(newFolder + fileName + '.png')
def animateRawData(data, params, fps=10, bitrate=14400, containerType='.mkv'):
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import Axes3D
nData = params['nSteps']/params['dataInterval']
n = params['n']
fig = plt.figure(facecolor='w')
plt.figtext(0.5, 0.92 ,'Evolution of adjacency matrix in preferential attachment model', ha='center', fontsize=16)
spAxes = [fig.add_subplot(i, projection='3d') for i in range(221, 225)]
spAxes[0].view_init(-2.0, 45.0)
spAxes[1].view_init(-2, 135)
spAxes[2].view_init(45, 225)
#find max degree to set z limits:
maxDeg = np.amax(data[:,:])
for ax in spAxes:
ax.set_xlim3d(left=0, right=n)
ax.set_ylim3d(bottom=0, top=n)
ax.set_zlim3d(bottom=0, top=maxDeg)
xgrid, ygrid = np.meshgrid(np.arange(n),np.arange(n))
newFolder = makeFolder('animations')
for i in range(nData):
for ax in spAxes:
ax.scatter(xgrid, ygrid, data[(i)*n:(i+1)*n,:n], c=data[(i)*n:(i+1)*n,:n], cmap='jet')
plt.draw()
fileName = genFileName('rawData3d', params, str(i))
plt.savefig(newFolder + fileName + '.png')
def animateReconstruction(data, params, fps=10, bitrate=1600, containerType='.mkv'):
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import Axes3D
n = params['n']
nData = data.shape[0]/n
fig = plt.figure(facecolor='w')
ax1 = fig.add_subplot(211, projection='3d')
ax2 = fig.add_subplot(212, projection='3d')
ax1.grid(b=False)
ax2.grid(b=False)
#find max degree to set z limits:
maxDeg = np.amax(data[:,:])
ax1.set_xlim3d(left=0, right=n)
ax1.set_ylim3d(bottom=0, top=n)
ax1.set_zlim3d(bottom=0, top=maxDeg)
ax2.set_xlim3d(left=0, right=n)
ax2.set_ylim3d(bottom=0, top=n)
ax2.set_zlim3d(bottom=0, top=maxDeg)
xgrid, ygrid = np.meshgrid(np.arange(n),np.arange(n))
newFolder = makeFolder('reconstruction')
print newFolder
fileName = ""
for i in range(nData):
z = data[(i)*n:(i+1)*n,:n]
zRecon = gGP.getEigenReconstruction(z)
ax1.scatter(xgrid, ygrid, z, c=z, cmap='jet')
ax2.scatter(xgrid, ygrid, zRecon, c=zRecon, cmap='RdBu')
fileName = genFileName('rawDataAndReconstruction', params, str(i))
plt.draw()
plt.savefig(newFolder + fileName + '.png')
ax1.cla()
ax2.cla()
ax1.grid(b=False)
ax2.grid(b=False)
ax1.set_xlim3d(left=0, right=n)
ax1.set_ylim3d(bottom=0, top=n)
ax1.set_zlim3d(bottom=0, top=maxDeg)
ax2.set_xlim3d(left=0, right=n)
ax2.set_ylim3d(bottom=0, top=n)
ax2.set_zlim3d(bottom=0, top=maxDeg)
print 1.0*(i+1)/nData
makeAnimation(fileName, newFolder)
def makeAnimation(inputFilename, inputFolder, fps=50, bitrate=3000000, containerType='.mkv'):
from subprocess import call
us1 = 1
us2 = 0
while us1 > 0:
us2 = us1
us1 = inputFilename.find("_", us2+1)
fileNamebase = inputFilename[:us2+1]
inputFiles = fileNamebase + "%d.png"
outputFilename = fileNamebase + containerType
os.chdir(os.path.realpath(inputFolder))
call(["ffmpeg", "-i", inputFiles, "-r", str(fps), "-b", str(bitrate), outputFilename])
def plotCRecon(data, params):
from mpl_toolkits.mplot3d import Axes3D
n = params['n']
nData = data.shape[0]/(2*n)
fig = plt.figure(facecolor='w')
ax1 = fig.add_subplot(211, projection='3d')
ax2 = fig.add_subplot(212, projection='3d')
xgrid, ygrid = np.meshgrid(np.arange(n),np.arange(n))
maxDeg = np.amax(data)
ax1.set_xlim(left=0, right=n)
ax1.set_ylim(bottom=0, top=n)
ax1.set_zlim(bottom=0, top=maxDeg)
ax2.set_xlim(left=0, right=n)
ax2.set_ylim(bottom=0, top=n)
ax2.set_zlim(bottom=0, top=maxDeg)
newFolder = makeFolder('CRecon')
print '--> saving', nData, 'images in', newFolder
fileName = ''
for i in range(nData):
preRecon = data[n*2*i:n*(2*i+1),:]
postRecon = data[n*(2*i+1):n*(2*i+2),:]
ax1.scatter(xgrid, ygrid, preRecon, c=preRecon, cmap='jet')
ax2.scatter(xgrid, ygrid, postRecon, c=postRecon, cmap='jet')
plt.draw()
fileName = genFileName('CRecon', params, uniqueID=str(i))
plt.savefig(newFolder + fileName + '.png')
ax1.cla()
ax2.cla()
ax1.grid(b=False)
ax2.grid(b=False)
ax1.set_xlim3d(left=0, right=n)
ax1.set_ylim3d(bottom=0, top=n)
ax1.set_zlim3d(bottom=0, top=maxDeg)
ax2.set_xlim3d(left=0, right=n)
ax2.set_ylim3d(bottom=0, top=n)
ax2.set_zlim3d(bottom=0, top=maxDeg)
makeAnimation(fileName, newFolder)
def compare_recon(data_list, params):
# expects a bunch of projData csv files in which
# data is layered in before_proj, after_proj
# adjacency matrices, the degree distributions of which
# are subtracted and plotted to give a sense of the errors
# in the reconstruction process
import matplotlib.cm as cm
import matplotlib.colors as colors
n = params['n']
ndata = len(data_list)
print ndata
npts = (data_list[0]).shape[0]/(2*n)
err = np.empty(npts)
max_err = np.empty(npts)
avg_err = np.empty(npts)
# avg the data, then plot
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
colornorm = colors.Normalize(vmin=0, vmax=npts-1)
colormap = cm.ScalarMappable(norm=colornorm, cmap='jet')
for i in range(npts):
preRecon = np.zeros((n,n))
postRecon = np.zeros((n,n))
for k in range(ndata):
preRecon = preRecon + data_list[k][n*2*i:n*(2*i+1),:]
postRecon = postRecon + data_list[k][n*(2*i+1):n*(2*i+2),:]
preRecon = preRecon / float(ndata)
postRecon = postRecon / float(ndata)
pre_recon_degs = np.sum(preRecon, 0)
post_recon_degs = np.sum(postRecon, 0)
if i == 0 or i == npts-1:
ax.plot(range(n), np.sort(pre_recon_degs) - np.sort(post_recon_degs), c=colormap.to_rgba(float(i)), lw=5)
else:
ax.plot(range(n), np.sort(pre_recon_degs) - np.sort(post_recon_degs), c=colormap.to_rgba(float(i)))
pre_sort = np.argsort(pre_recon_degs)
post_sort = np.argsort(post_recon_degs)
preRecon = preRecon[pre_sort, :]
preRecon = preRecon[:, pre_sort]
postRecon = postRecon[post_sort, :]
postRecon = postRecon[:, post_sort]
err[i] = np.linalg.norm(preRecon - postRecon)
max_err[i] = np.max(preRecon - postRecon)
avg_err[i] = np.average(preRecon - postRecon)
ax.set_xlabel('index', fontsize=24)
ax.set_ylabel('degree difference (actual - reconstruction)', fontsize=30)
ax.tick_params(axis='both', which='major', labelsize=24)
plt.show()
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
ax.plot(range(npts), err, c='c', label='cumulative')
ax.plot(range(npts), avg_err, c='g', label='average')
ax.plot(range(npts), max_err, c='r', label='maximum single-degree')
ax.set_ylim(bottom=0)
ax.set_xlabel('approximate time')
ax.set_ylabel('reconstruction error')
print '--> saving images in recon_comp'
plt.savefig('./recon_comp/recon_comp.png')
def plotEigVectRecon(data, params):
n = params['n']
nData = data.shape[0]/(2)
fig = plt.figure(facecolor='w')
ax1 = fig.add_subplot(111)
yMin = np.amin(data)
yMax = np.amax(data)
#ax1.set_ylim((yMin, yMax))
xData = np.linspace(1, n, n)
folderName = makeFolder("eigVectRecon")
print folderName
for i in range(nData):
ax1.set_xlabel('index')
ax1.set_ylabel('vector value')
# ax1.plot(xData, data[2*i*n: n*(2*i+1)])
# ax1.plot(xData, data[n*(2*i+1): 2*n*(i+1)], c='g')
ax1.hold(True)
ax1.plot(xData, data[i,:], c='k')
ax1.plot(xData, data[nData+i,:], c='g')
plt.savefig(folderName + genFileName("eigVectRecon", params, uniqueID=str(i)) + '.png')
ax1.cla()
def plotFittedData(data, params, fns):
from mpl_toolkits.mplot3d import Axes3D
nData = params['nSteps']/params['dataInterval']
n = params['n']
fig = plt.figure(facecolor='w')
fig.hold(True)
spAxes = [fig.add_subplot(i, projection='3d') for i in range(221, 225)]
spAxes[0].view_init(-2.0, 45.0)
spAxes[1].view_init(-2, 135)
spAxes[2].view_init(45, 225)
xyScaling = 100.0
xgrid = xgrid/xyScaling
ygrid = ygrid/xyScaling
#find max degree for axis limits
maxDeg = np.amax(data[:,:])
for ax in spAxes:
ax.set_xlim3d(left=0, right=n/xyScaling)
ax.set_ylim3d(bottom=0, top=n/xyScaling)
ax.set_zlim3d(bottom=0, top=maxDeg)
#don't plot each f(x,y) in wireframe
stride = 10
newFolder = makeFolder('fittedPlots')
for i in range(nData):
Z = np.transpose(data[(i)*n:(i+1)*n,:n])
fn = gGP.fitXYFunction(xgrid, ygrid, Z, fns)
for ax in spAxes:
ax.scatter(xgrid, ygrid, Z, c=Z, cmap='jet', alpha=0.1)
ax.plot_wireframe(xgrid, ygrid, fn(xgrid, ygrid), rstride=stride, cstride=stride)
plt.draw()
fileName = genFileName('fittedPlot', params, str(i))
plt.savefig(newFolder + fileName + '.png')
def animateVector(data, params, fn, fps=10, bitrate=14400, containerType='.mkv'):
n = params['n']
nData = data.shape[0]/n
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
ax.set_xlabel('Vector index')
ax.set_ylabel('Vector value')
newFolder = makeFolder('vector')
print newFolder
fileName = ""
#find y upper and lower limits
yMin = np.min([fn(data[(i)*n:(i+1)*n,:n]) for i in range(nData)])
yMax = np.max([fn(data[(i)*n:(i+1)*n,:n]) for i in range(nData)])
for i in range(nData):
ax.cla()
ax.set_xlabel('Vector index')
ax.set_ylabel('Vector value')
ax.set_ylim((yMin, yMax))
ax.plot(np.linspace(1,n,n), fn(data[(i)*n:(i+1)*n,:n]), marker='o', c=[1,0.5,0.5])
fileName = genFileName('eigVals', params, str(i))
plt.savefig(newFolder + fileName + '.png')
makeAnimation(fileName, newFolder)
def comp_eigvect_recon(coeffs, params, plot_name=""):
n = params['n']
proj_step = params['proj_step']
wait = params['off_manifold_wait']
nmicrosteps = params['nms']
collect_interval = params['collection_interval']
nsaves_per_proj = (nmicrosteps - wait)/collect_interval + 2
nprojs = (data.shape[0] - 1)/nsaves_per_proj
print nprojs, nsaves_per_proj
nvects = data.shape[1]
nyvects = nvects - 1
if plot_name is not "":
plot_name = plot_name + "_"
line = np.arange(n)
for i in range(nprojs):
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
for j in range(nsaves_per_proj):
recon = np.zeros(n)
for k in range(nyvects-1, -1, -1):
recon = recon*line + coeffs[i*nsaves_per_proj + j][k]
if j == nsaves_per_proj-1:
ax.plot(range(n), recon, c='r')
else:
ax.plot(range(n), recon, c='b')
ax.set_title('reconstructions over time')
plt.savefig("eigvect_recon/" + plot_name + "eigvect_recon" + str(i) + ".png")
def animate_eigvals(eigvals, params, fps=10, bitrate=14400, containerType='.mkv'):
n = params['n']
nvects = eigvals.shape[0]
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
ax.set_xlabel('Index')
ax.set_ylabel('Eigenvalue')
newFolder = makeFolder('eigenvalues')
print 'saved in', newFolder
fileName = ""
#find y upper and lower limits
yMin = np.min(eigvals)
yMax = np.max(eigvals)
for i in range(nvects):
ax.cla()
ax.set_xlabel('Index')
ax.set_ylabel('Eigenvalue')
# ax.set_ylim((yMin, yMax))
ax.plot(np.arange(n), np.sort(np.log(np.abs(data[i, :]))), marker='o', c=[1,0.5,0.5])
fileName = genFileName('eigvals', params, str(i))
plt.savefig(newFolder + fileName + '.png')
makeAnimation(fileName, newFolder)
def scalarEvolution(data, params, fn):
nData = params['nSteps']/params['dataInterval']
stepSize = params['dataInterval']
n = params['n']
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
newFolder = makeFolder('vector')
fileName = ""
yData = np.array([fn(data[(i)*n:(i+1)*n,:n]) for i in range(nData)])
xData = np.array([i*stepSize for i in range(nData)])
ax.plot(xData, yData, color='g', marker='o')
fileName = genFileName('scalarEvo', params, str(i))
newFolder = makeFolder('scalarEvo')
plt.savefig(newFolder + fileName + ".png")
def plotReconstruction((x, y, z, zlim, xylim, folder, fileName)):
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(facecolor='w')
ax1 = fig.add_subplot(211, projection='3d')
ax2 = fig.add_subplot(212, projection='3d')
ax1.grid(b=False)
ax2.grid(b=False)
ax1.set_xlim3d(left=0, right=xylim)
ax1.set_ylim3d(bottom=0, top=xylim)
ax1.set_zlim3d(bottom=0, top=zlim)
ax2.set_xlim3d(left=0, right=xylim)
ax2.set_ylim3d(bottom=0, top=xylim)
ax2.set_zlim3d(bottom=0, top=zlim)
ax1.scatter(x, y, z, c=z, cmap='jet')
ax2.scatter(x, y, gGP.getEigenReconstruction(z), c=z, cmap = 'jet')
plt.savefig(folder + fileName + ".png")
plt.close(fig)
def compareProjection(fullData, fullParams, cpiData, cpiParams):
#3d plot of full simulation and cpi, degree evolution vs time
from mpl_toolkits.mplot3d import Axes3D
n = fullParams['n']
nFullData = fullData.shape[0]/n
nCPIData = cpiData.shape[0]/n
#full collection interval
fullCI = fullParams['dataInterval']
#cpi collection interval
cpiCI = cpiParams['collectInterval']
cpiNMS = cpiParams['nMicroSteps']
cpiOMW = cpiParams['offManifoldWait']
cpiProjStep = cpiParams['projStep']
#on manifold steps, with any luck is an integer
cpiOMS = (cpiNMS - cpiOMW)/cpiCI
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111, projection='3d')
ax.set_zlabel('degree')
ax.set_ylabel('steps')
ax.set_xlabel('vertex index')
xData = np.linspace(1,n,n)
for i in range(nFullData):
time = i*fullCI*np.ones(n)
ax.plot(xData, time, gGP.getDegrees(fullData[i*n:(i+1)*n,:]), c='r', alpha=0.1)
t = cpiOMW
onManifoldCount = 0
for i in range(nCPIData):
time = t*np.ones(n)
if onManifoldCount < cpiOMS:
t = t + cpiCI
onManifoldCount = onManifoldCount + 1
else:
t = t + cpiProjStep + cpiOMW
onManifoldCount = 0
ax.plot(xData, time, gGP.getDegrees(cpiData[i*n:(i+1)*n,:]), c='b', alpha=0.1)
newFolder = makeFolder('compProj')
plt.savefig(newFolder + 'compProj.png')
def makeDegSurface(data, params, fn):
from mpl_toolkits.mplot3d import Axes3D
n = params['n']
nData = data.shape[0]/n
fig = plt.figure(facecolor='w')
fig2 = plt.figure(facecolor='w')
ax2 = fig2.add_subplot(111, projection='3d')
fig.hold(True)
#spAxes = [fig.add_subplot(i, projection='3d') for i in range(211, 213)]
spAxes = [fig.add_subplot(111, projection='3d')]
spAxes[0].view_init(30, -135)
ax2.view_init(30, -135)
maxZ = np.max([np.max(fn(data[i*n:(i+1)*n,:])) for i in range(nData)])
ci = params['dataInterval']
tSpan = nData*ci
nNCubedSteps = tSpan/np.power(n, 3)
nNSqSteps = np.power(n, 2)/ci
#set various axis properties
#[ax.grid(b=False) for ax in spAxes]
[ax.set_xlim((0, n)) for ax in spAxes]
[ax.set_xticklabels([str(n)]) for ax in spAxes]
[ax.set_xticks([n]) for ax in spAxes]
[ax.set_xlabel('vertex index') for ax in spAxes]
[ax.set_ylim((1, tSpan)) for ax in spAxes]
[ax.set_yticks([str(i) for i in (np.power(n, 3)*np.arange(nNCubedSteps))]) for ax in spAxes]
[ax.set_yticklabels([str(i) for i in (np.power(n, 3)*np.arange(nNCubedSteps))]) for ax in spAxes]
[ax.set_ylabel('simulation step') for ax in spAxes]
ax2.set_xlabel('vertex index')
ax2.set_ylabel('simulation step')
ax2.set_zlabel('degree')
# [ax.set_zlim((0, maxZ)) for ax in spAxes]
# [ax.set_zticklabels([str(maxZ)]) for ax in spAxes]
# [ax.set_zticks([maxZ]) for ax in spAxes]
[ax.set_zlabel('degree') for ax in spAxes]
# [ax.set_zscale('log') for ax in spAxes]
xData = np.linspace(1, n, n)
for i in range(nData):
ys = ci*(i+1)*np.ones(n)
color = 'b'
if (i+1)*params['dataInterval'] % (np.power(params['m'], 3)) == 0:
color = 'r'
if((i+1)*ci % np.power(n, 3) == 0):
[ax.plot(xData, ys, np.log(1+fn(data[i*n:(i+1)*n])), c=color, alpha=0.5) for ax in spAxes]
if(i*ci < np.power(n, 3)):
ax2.plot(xData, ys, np.log(1+fn(data[i*n:(i+1)*n])), c=color, alpha=0.5)
newFolder =makeFolder('vectorSurface')
fig.savefig(newFolder + 'degreeSurfacen3.png')
fig2.savefig(newFolder + 'degreeSurfacen2.png')
def plot_coeffs(times, coeffs_list, plot_name=""):
coeffs = np.average(np.array(coeffs_list), 0)
n = coeffs.shape[0]
ncoeffs = coeffs.shape[1]
if plot_name is not "":
plot_name = plot_name + "_"
for i in range(ncoeffs):
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
ax.scatter(times, coeffs[:,i], lw=0)
maxcoeff = np.amax(coeffs[:,i])
mincoeff = np.amin(coeffs[:,i])
ax.set_ylim((mincoeff - 0.1*(maxcoeff - mincoeff), maxcoeff + 0.1*(maxcoeff - mincoeff)))
plt.savefig("coeffs/" + plot_name + "coeff" + str(i) + ".png")
def plot_coeffs_fitting(times, coeffs_list, fit, plot_name=""):
coeffs = np.average(np.array(coeffs_list), 0)
n = coeffs.shape[0]
ncoeffs = coeffs.shape[1]
nfitcoeffs = fit.shape[1]
if plot_name is not "":
plot_name = plot_name + "_"
for i in range(ncoeffs):
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
ax.scatter(times, coeffs[:,i], lw=0, c='b')
evals = np.zeros(n)
for j in range(nfitcoeffs-1, 0, -1):
evals = 10.0*((np.linspace(10000, 200000, n) - 10000)/80000)*(evals + fit[i,j])
evals = evals + np.ones(n)*fit[i,0]
ax.plot(np.linspace(10000, 200000, n), evals, color='g')
maxcoeff = np.amax(coeffs[:,i])
mincoeff = np.amin(coeffs[:,i])
ax.set_ylim((mincoeff - 0.1*(maxcoeff - mincoeff), maxcoeff + 0.1*(maxcoeff - mincoeff)))
ax.set_xlim((0,2*200000))
plt.savefig("coeffs/" + plot_name + "coeff" + str(i) + ".png")
def plot_vectors_tc(data, params, plot_name=""):
""" Assumes data is arranged as:
vector1 vector2 vector3 ... vectorN times
data[0] data[1] data[2] data[N-2] data[N-1]
and plots vectors against times
"""
proj_step = params['proj_step']
wait = params['off_manifold_wait']
nmicrosteps = params['nms']
collect_interval = params['collection_interval']
nsaves_per_proj = (nmicrosteps - wait)/collect_interval + 2
nprojs = (data.shape[0] - 1)/nsaves_per_proj
print nprojs, nsaves_per_proj
nvects = data.shape[1]
nyvects = nvects - 1
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
if plot_name is not "":
plot_name = plot_name + "_"
for i in range(nyvects):
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
for j in range(nprojs):
ax.scatter(data[j*nsaves_per_proj:(j+1)*nsaves_per_proj,nyvects], data[j*nsaves_per_proj:(j+1)*nsaves_per_proj,i], c=(np.sin(float(i)/nyvects), np.cos(float(1-i)/nyvects), 1-float(i)/nyvects), label="coeff: " + str(i+1), lw=0)
ax.scatter(np.arange(1, nprojs+1)*(nmicrosteps + proj_step), data[np.arange(nprojs)*nsaves_per_proj + nsaves_per_proj - 1, i], lw=0, s=30, c='r')
ax.set_xlabel('simulation step')
ax.set_ylabel('coefficient value')
ax.set_xlim(left=0)
plt.savefig("coeffs/" + plot_name + "coeff" + str(i) + ".png")
#ax.legend(loc=6)
def plot_degree_surface(degs, times, sort=True, title='', zlabel=None, ax=None, FONTSIZE=48, zlim=None, colornorm=None):
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.cm as cm
import matplotlib.colors as colors
import matplotlib.colorbar as colorbar
LABELSIZE = 0.65*FONTSIZE
LEGENDSIZE = 0.5*FONTSIZE
ALPHA = 0.8
new_npts = 50
times.shape = (times.shape[0], 1)
times = thin_array(times, new_npts=new_npts)
degs = thin_array(degs, new_npts=new_npts)
if sort:
sorted_degs = np.sort(degs)
else:
sorted_degs = degs
n = degs.shape[1]
indices = np.linspace(1, n, n)
maxdeg = np.amax(sorted_degs)
mindeg = np.amin(sorted_degs)
# color by deg (z val), not vertex (x val)
# colornorm = colors.Normalize(vmin=0, vmax=n-1)
if colornorm is None:
colornorm = colors.Normalize(vmin=mindeg, vmax=maxdeg)
colormap = cm.ScalarMappable(norm=colornorm, cmap='jet')
ntimes = times.shape[0]
show = False
if ax is None:
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111, projection='3d')
show = True
npts = times.shape[0]
for v in range(n):
ax.scatter(v*np.ones(npts), times, sorted_degs[:,v], linewidths=0, c='b')#colormap.to_rgba(1.0*sorted_degs[:,v])) # *v))
ax.set_xlim((0,n))
ax.set_xticklabels([str(int(i)) for i in np.linspace(1, n, 6)])
ax.set_ylim(bottom=0)
if zlim is None:
zlim = (mindeg-(maxdeg-mindeg)*0.1, maxdeg+(maxdeg-mindeg)*0.1)
ax.set_zlim(zlim)
else:
ax.set_zlim(zlim)
ax.ticklabel_format(axis='y', style='sci', scilimits=(-2, 2))
ax.tick_params(axis='both', which='major', labelsize=LABELSIZE)
ax.tick_params(axis='both', which='minor', labelsize=LABELSIZE)
ax.set_xlabel('\nvertex', fontsize=FONTSIZE)
ax.set_ylabel('\nstep', fontsize=FONTSIZE)
if zlabel is None:
zlabel = 'degree'
ax.set_zlabel(zlabel, fontsize=FONTSIZE)
ax.set_title(title, fontsize=FONTSIZE)
# increase size of axes scaling number and add padding
# scale_pos = ax.yaxis.get_children()[1].get_position()
# print ax.yaxis.get_children()[1]
# ax.yaxis.get_children()[1].set_text("\n" + str(scale_txt))
ax.yaxis.get_children()[1].set_size(0)
# SUPER DAMN STUPID, BUT I DON'T KNOW HOW TO PROGRAMMATICALLY FIND THE EXPONENTIAL SCALE VALUE
# DAMMIT
print "******************************"
print "watch yo damn self, the axis scale '1e7' has been added by hand and may not be correct"
print "final time =", times[-1]
print "******************************"
print n
ax.text(1.1*n, times[-1], zlim[0]-0.3*(zlim[1] - zlim[0]), '1e8', fontsize=LABELSIZE, zorder=5)
# scale_txt = ax.yaxis.get_children()[1].get_text()
# ax.yaxis.get_children()[1].set_position((1, -0.1))
# ax.yaxis.get_children()[1].set_va('bottom')
if show:
fig.tight_layout()
plt.show()
return zlim
def plot_degree_surface_v2(degs, times):
# this method has become overly specialized: it plots many different things, none of which, in fact, is a degree surface
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.cm as cm
import matplotlib.colors as colors
import matplotlib.colorbar as colorbar
import matplotlib.gridspec as gs
n = params['n']
ci = params['dataInterval']
indices = np.linspace(1, n, n)
colornorm = colors.Normalize(vmin=0, vmax=n-1)
colorbarnorm = colors.Normalize(vmin=0, vmax=100)
colormap = cm.ScalarMappable(norm=colornorm, cmap='jet')
#add ones vector
data_count = 0
ntimes = times.shape[0]
max_degs = [np.max(degs[i,:]) for i in range(ntimes)]
NPLOTTED_PTS = 15
PLOT_INTERVAL = int(ntimes/NPLOTTED_PTS)
FONTSIZE = 20
LABELSIZE = 16
fig1 = plt.figure(facecolor='w')
ax1_ = fig1.add_subplot(111, projection='3d')
ax1_.set_xlabel('percentile', fontsize=FONTSIZE)
ax1_.set_ylabel('step', fontsize=FONTSIZE)
ax1_.set_zlabel('vertex degree', fontsize=FONTSIZE)
sorted_degs = np.sort(degs, 1)
#trimmed_degs = sorted_degs
time_limit = 2*np.power(n, 3)
interval_times = []
trimmed_degs = []
i = 0
while times[i] <= time_limit:
interval_times.append(times[i])
trimmed_degs.append(sorted_degs[i])
i = i + 1
interval_times = np.array(interval_times)
trimmed_degs = np.array(trimmed_degs)
npoints = trimmed_degs.shape[0]
NPLOTTED_PTS = 15
ones = np.ones(NPLOTTED_PTS)
PLOT_INTERVAL = int(npoints/NPLOTTED_PTS)
for v in range(n):
# ax1_.scatter(100.0*v*ones/n, interval_times[[i*PLOT_INTERVAL for i in range(NPLOTTED_PTS)]], trimmed_degs[[i*PLOT_INTERVAL for i in range(NPLOTTED_PTS)],v], linewidths=0, c=colormap.to_rgba(1.0*v))
ax1_.scatter(100.0*v*ones/n, interval_times[[i*PLOT_INTERVAL for i in range(NPLOTTED_PTS)]], trimmed_degs[[i*PLOT_INTERVAL for i in range(NPLOTTED_PTS)], v], linewidths=0, c=colormap.to_rgba(1.0*v))
ax1_.scatter(100.0*v/n, interval_times[-1], trimmed_degs[-1, v], linewidths=0, c=colormap.to_rgba(1.0*v))
ax1_.set_xlim(left=0, right = 100)
ax1_.set_ylim(bottom=0)
ax1_.set_zlim(bottom=0)
# plt.show()
fig2 = plt.figure(facecolor='w')
ax1_ = fig2.add_subplot(111, projection='3d')
ax1_.set_xlabel('percentile', fontsize=FONTSIZE)
ax1_.set_ylabel('step', fontsize=FONTSIZE)
ax1_.set_zlabel('vertex degree', fontsize=FONTSIZE)
# sorted_degs = np.log(np.sort(degs, 1)+1)
sorted_degs = np.sort(degs, 1)
#trimmed_degs = sorted_degs
time_limit = 2*np.power(n, 3)
interval_times = []
i = 0
interval_times = np.array(interval_times)
NPLOTTED_PTS = 15
ones = np.ones(NPLOTTED_PTS)
PLOT_INTERVAL = int(ntimes/NPLOTTED_PTS)
for v in range(n):
# ax1_.scatter(100.0*v*ones/n, interval_times[[i*PLOT_INTERVAL for i in range(NPLOTTED_PTS)]], trimmed_degs[[i*PLOT_INTERVAL for i in range(NPLOTTED_PTS)],v], linewidths=0, c=colormap.to_rgba(1.0*v))
ax1_.scatter(100.0*v*ones/n, times[[i*PLOT_INTERVAL for i in range(NPLOTTED_PTS)]], sorted_degs[[i*PLOT_INTERVAL for i in range(NPLOTTED_PTS)], v], linewidths=0, c=colormap.to_rgba(1.0*v))
ax1_.scatter(100.0*v/n, times[-1], sorted_degs[-1, v], linewidths=0, c=colormap.to_rgba(1.0*v))
ax1_.set_xlim(left=0, right = 100)
ax1_.set_ylim(bottom=0)
ax1_.set_zlim(bottom=0)
#n3
deg_diff = []
for i in range(NPLOTTED_PTS):
deg_diff.append(sorted_degs[i*PLOT_INTERVAL, :] - sorted_degs[(i+1)*PLOT_INTERVAL, :])
deg_diff = np.array(deg_diff)
fig13 = plt.figure(facecolor='w')
ax = fig13.add_subplot(111)
colornorm = colors.Normalize(vmin=0, vmax=NPLOTTED_PTS-1)
colormap = cm.ScalarMappable(norm=colornorm, cmap='RdBu')
alphaval = 0.1
for time in range(NPLOTTED_PTS):
ax.scatter(indices, deg_diff[time], linewidths=0, c=colormap.to_rgba(1.0*time), alpha=alphaval)
ax.set_xlabel('percentile', fontsize=FONTSIZE)
ax.set_ylabel('change in degree', fontsize=FONTSIZE)
ax.set_xlim((0, n))
ax.set_xticks([i for i in np.linspace(0, n, 11)])
ax.set_xticklabels([str(i) for i in np.linspace(0, 100, 11)])
ax.tick_params(axis='both', which='major', labelsize=LABELSIZE)
#n2
deg_diff = []
PLOT_INTERVAL = int(npoints/NPLOTTED_PTS)
for i in range(NPLOTTED_PTS):
deg_diff.append(sorted_degs[i*PLOT_INTERVAL, :] - sorted_degs[(i+1)*PLOT_INTERVAL, :])
deg_diff = np.array(deg_diff)
fig14 = plt.figure(facecolor='w')
ax = fig14.add_subplot(111)
for time in range(NPLOTTED_PTS):
ax.scatter(indices, deg_diff[time], linewidths=0, c=colormap.to_rgba(1.0*time), alpha=alphaval)
ax.set_xlabel('percentile', fontsize=FONTSIZE)
ax.set_ylabel('change in degree', fontsize=FONTSIZE)
ax.set_xlim((0, n))
ax.set_xticks([i for i in np.linspace(0, n, 11)])
ax.set_xticklabels([str(i) for i in np.linspace(0, 100, 11)])
ax.tick_params(axis='both', which='major', labelsize=LABELSIZE)
#continue
colornorm = colors.Normalize(vmin=0, vmax=n-1)
colorbarnorm = colors.Normalize(vmin=0, vmax=100)
colormap = cm.ScalarMappable(norm=colornorm, cmap='jet')
fig6 = plt.figure(facecolor='w')
# trimmed_degs = sorted_degs
ax6_ = fig6.add_subplot(111)
PLOT_INTERVAL = int(npoints/NPLOTTED_PTS)
for time in range(NPLOTTED_PTS):
ax6_.scatter(indices , trimmed_degs[time*PLOT_INTERVAL,:], linewidths=0, c=indices, alpha=1.0*time/NPLOTTED_PTS/5.0)
ax6_.set_xlabel('percentile', fontsize=FONTSIZE)
ax6_.set_ylabel('degree', fontsize=FONTSIZE)
ax6_.set_xlim((0, n))
ax6_.set_ylim(bottom=0)
ax6_.set_xticks([i for i in np.linspace(0, n, 11)])
ax6_.set_xticklabels([str(i) for i in np.linspace(0, 100, 11)])
ax6_.tick_params(axis='both', which='major', labelsize=LABELSIZE)
plt.show()
fig7 = plt.figure(facecolor='w')
ax6_ = fig7.add_subplot(111)
PLOT_INTERVAL = int(ntimes/NPLOTTED_PTS)
for time in range(NPLOTTED_PTS):
ax6_.scatter(indices , sorted_degs[time*PLOT_INTERVAL,:], linewidths=0, c=indices, alpha=1.0*time/NPLOTTED_PTS/5.0)
ax6_.set_xlabel('percentile', fontsize=FONTSIZE)
ax6_.set_ylabel('degree', fontsize=FONTSIZE)
ax6_.set_xlim((0, n))
ax6_.set_ylim(bottom=0)
ax6_.set_xticks([i for i in np.linspace(0, n, 11)])
ax6_.set_xticklabels([str(i) for i in np.linspace(0, 100, 11)])
ax6_.tick_params(axis='both', which='major', labelsize=LABELSIZE)
plt.show()
# for v in range(n):
# ax6_.scatter(100.0*v*ones/n, trimmed_degs[[i*PLOT_INTERVAL for i in range(NPLOTTED_PTS)],v], linewidths=0, c=colormap.to_rgba(1.0*v), alpha= 1.0*v/n)
#def holdout():
# fig2 = plt.figure(facecolor='w')
# ax2_ = fig2.add_subplot(111)
# ax2_.set_xlabel('simulation step', fontsize=FONTSIZE)
# ax2_.set_ylabel('max vertex degree', fontsize=FONTSIZE)
# ax2_.plot(times, max_degs)
# plt.show()
#fig 3 is a mess in order to get the colormap and colobars working, requires many of the imports seen at the beginning of the fn
fig3 = plt.figure(facecolor='w')
gspec = gs.GridSpec(6,6)
ax31_ = fig3.add_subplot(gspec[:6,:5])
maxtime = times[-1]
ax31_.set_xticks([i*maxtime/10.0 for i in range(11)])
ax32_ = fig3.add_subplot(gspec[:,5])
ax31_.set_xlabel('simulation step', fontsize=FONTSIZE)
ax31_.set_ylabel('vertex degree', fontsize=FONTSIZE)
ax31_.hold(True)
artist = []
for v in range(n):
ax31_.plot(times, sorted_degs[:,v], c=colormap.to_rgba(1.0*v))
cb = colorbar.ColorbarBase(ax32_, cmap='jet', norm=colorbarnorm, orientation='vertical')
ax31_.tick_params(axis='both', which='major', labelsize=LABELSIZE)
ax31_.tick_params(axis='both', which='minor', labelsize=LABELSIZE)
ax32_.tick_params(axis='both', which='major', labelsize=LABELSIZE)
ax32_.tick_params(axis='both', which='minor', labelsize=LABELSIZE)
# cb.set_label('pseudo vertex label')
fig3.text(0.8, 0.93, 'percentile', fontsize=FONTSIZE-4)
plt.show()
max_index = 0
while times[max_index] < 10*np.power(n, 3):
max_index = max_index + 1
# fig4 = plt.figure(facecolor='w')
# ax41_ = fig4.add_subplot(gspec[:6,:5])
# ax42_ = fig4.add_subplot(gspec[:,5])
# ax41_.set_xlabel('simulation step', fontsize=FONTSIZE)
# ax41_.set_ylabel('vertex degree', fontsize=FONTSIZE)
# ax41_.hold(True)
# for v in range(n):
# ax41_.plot(times[:max_index], sorted_degs[:max_index,v], c=colormap.to_rgba(1.0*v))
# cb = colorbar.ColorbarBase(ax42_, cmap='jet', norm=colorbarnorm, orientation='vertical')
# ax41_.tick_params(axis='both', which='major', labelsize=LABELSIZE)
# ax41_.tick_params(axis='both', which='minor', labelsize=LABELSIZE)
# ax42_.tick_params(axis='both', which='major', labelsize=LABELSIZE)
# ax42_.tick_params(axis='both', which='minor', labelsize=LABELSIZE)
# # cb.set_label('pseudo vertex label')
# fig4.text(0.8, 0.93, 'percentile', fontsize=FONTSIZE-4)
# plt.show()
time_limit = 2*np.power(n, 3)
interval_times = []
trimmed_degs = []
i = 0
while times[i] <= time_limit:
interval_times.append(times[i])
trimmed_degs.append(sorted_degs[i])
i = i + 1
interval_times = np.array(interval_times)
trimmed_degs = np.array(trimmed_degs)
maxtime = interval_times[-1]
fig5 = plt.figure(facecolor='w')
ax51_ = fig5.add_subplot(gspec[:6,:5])
ax52_ = fig5.add_subplot(gspec[:,5])
ax51_.set_xlabel('simulation step', fontsize=FONTSIZE)
ax51_.set_ylabel('vertex degree', fontsize=FONTSIZE)
ax51_.hold(True)
for v in range(n):
ax51_.plot(interval_times, trimmed_degs[:,v], c=colormap.to_rgba(1.0*v))
ax51_.set_xlim(right=maxtime)
ax51_.set_xticks([i*maxtime/10.0 for i in range(11)])
cb = colorbar.ColorbarBase(ax52_, cmap='jet', norm=colorbarnorm, orientation='vertical')
ax51_.tick_params(axis='both', which='major', labelsize=LABELSIZE)
ax51_.tick_params(axis='both', which='minor', labelsize=LABELSIZE)
ax52_.tick_params(axis='both', which='major', labelsize=LABELSIZE)
ax52_.tick_params(axis='both', which='minor', labelsize=LABELSIZE)
# cb.set_label('pseudo vertex label')
fig5.text(0.8, 0.93, 'percentile', fontsize=FONTSIZE-4)
plt.show()
def plot_time_projection_diff(degs, times):
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.cm as cm
import matplotlib.colors as colors
import matplotlib.colorbar as colorbar
import matplotlib.gridspec as gs
gspec = gs.GridSpec(6,6)
deg_diff = []
n = params['n']
ci = params['dataInterval']
indices = np.linspace(1, n, n)
colornorm = colors.Normalize(vmin=0, vmax=n-1)
colorbarnorm = colors.Normalize(vmin=0, vmax=100)
colormap = cm.ScalarMappable(norm=colornorm, cmap='jet')
data_count = 0
ntimes = times.shape[0]
max_degs = [np.max(degs[i,:]) for i in range(ntimes)]
NPLOTTED_PTS = 60
# n3
PLOT_INTERVAL = int(ntimes/NPLOTTED_PTS)
FONTSIZE = 48
LABELSIZE = 36
sorted_degs = np.sort(degs)
time_limit = np.power(n, 3)
interval_times = []
trimmed_degs = []
i = 0
while times[i] <= time_limit:
interval_times.append(times[i])
trimmed_degs.append(sorted_degs[i])
i = i + 1
interval_times = np.array(interval_times)
trimmed_degs = np.array(trimmed_degs)
npoints = trimmed_degs.shape[0]
for i in range(NPLOTTED_PTS):
deg_diff.append(sorted_degs[i*PLOT_INTERVAL, :] - sorted_degs[(i+1)*PLOT_INTERVAL, :])
deg_diff = np.array(deg_diff)
formatter = ticker.ScalarFormatter()
formatter.set_scientific(True)
formatter.set_powerlimits((-2, 2))
fig13 = plt.figure(facecolor='w')
ax = fig13.add_subplot(gspec[:6,:5])
ax2 = fig13.add_subplot(gspec[:,5])
colornorm = colors.Normalize(vmin=0, vmax=NPLOTTED_PTS-1)
colormap = cm.ScalarMappable(norm=colornorm, cmap='jet')
for time in range(NPLOTTED_PTS):
# ax.scatter(indices, deg_diff[time], linewidths=0, c=colormap.to_rgba(1.0*time), alpha=0.7)
ax.plot(indices, deg_diff[time], c=colormap.to_rgba(1.0*time))
colorbarnorm = colors.Normalize(vmin=0, vmax=times[-1])
cb = colorbar.ColorbarBase(ax2, cmap='jet', norm=colorbarnorm, orientation='vertical', format=formatter)
# ax2.ticklabel_format(style='sci')
ax2.yaxis.get_children()[1].set_size(LABELSIZE)
fig13.text(0.82, 0.94, 'time', fontsize=FONTSIZE-4)
ax.set_xlabel('percentile', fontsize=FONTSIZE)
ax.set_ylabel('change in degree', fontsize=FONTSIZE)
ax.set_xlim((0, n))
ax.set_xticks([i for i in np.linspace(0, n, 11)])
ax.set_xticklabels([str(i) for i in np.linspace(0, 100, 11)])
ax2.tick_params(axis='both', which='major', labelsize=LABELSIZE)