1+ #
2+ # Licensed to the Apache Software Foundation (ASF) under one or more
3+ # contributor license agreements. See the NOTICE file distributed with
4+ # this work for additional information regarding copyright ownership.
5+ # The ASF licenses this file to You under the Apache License, Version 2.0
6+ # (the "License"); you may not use this file except in compliance with
7+ # the License. You may obtain a copy of the License at
8+ #
9+ # http://www.apache.org/licenses/LICENSE-2.0
10+ #
11+ # Unless required by applicable law or agreed to in writing, software
12+ # distributed under the License is distributed on an "AS IS" BASIS,
13+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ # See the License for the specific language governing permissions and
15+ # limitations under the License.
16+ #
17+
118import numpy as np
219import matplotlib .pyplot as plt
320
421class Plot :
5- def plotCircles (self ):
6- # LABELS=self.getLabels()
22+
23+ def __init__ (self ):
24+ self .colors = ['b' , 'g' , 'r' , 'y' , 'm' , 'c' ]
25+
26+ def plotInputCircles (self , subplot = None ):
27+ myplt = subplot if subplot else plt
728 (labels ,x ,y ) = ([], [], [])
829 for (label , (xx ,yy )) in self .getCirclePoints ():
930 labels .append (int (label ))
1031 x .append (float (xx ))
1132 y .append (float (yy ))
1233
13- colors = ['b' , 'g' , 'r' ,'y' ,'w' , 'm' ]
14- norm = plt .normalize ()
15- norm .autoscale (x )
16- # norm.autoscale(y)
34+ myplt .set_title ('Labeled Input Data' ,fontsize = 'medium' )
35+ myplt .set_xlabel ('X' ,fontsize = 'small' )
36+ myplt .set_ylabel ('Y' ,fontsize = 'small' )
37+ myplt .set_xlim ([- 2.5 ,2.5 ])
38+ # norm = plt.normalize()
39+ # norm.autoscale(x)
1740 for (plabel , x , y ) in zip (labels ,x , y ):
18- xcolor = colors [- 1 + int (plabel / 1000 )]
19- lines = plt .plot (x , y , 'x' ,markersize = 3 ,color = xcolor )
20- plt .annotate (str (plabel ),xy = (x ,y ), xytext = (- 5 ,5 ),
41+ xcolor = self . colors [- 1 + int (plabel / 1000 )]
42+ myplt .plot (x , y , 'x' ,markersize = 3 ,color = xcolor )
43+ myplt .annotate (str (plabel ),xy = (x ,y ), xytext = (- 5 ,5 ),
2144 textcoords = 'offset points' ,
2245 arrowprops = dict (facecolor = xcolor , shrink = 0.01 ),
2346 horizontalalignment = 'right' , verticalalignment = 'bottom' ,
24- fontsize = 6
25- )
26- # plt.plot(x, y, 'o', markersize=1,color=colors[-1 + (plabel / 1000)], label= '%s' %plabel )
27- # plt.plot(x, y)
28- # plt.plot(x, y, color='y') # , markersize=1, label= '%s' %plabel )
47+ fontsize = 6 )
2948
30- plt .show ()
31- plt .savefig ('inputs.png' )
49+ myplt .tick_params (axis = 'both' , which = 'major' , labelsize = 8 )
50+ myplt .tick_params (axis = 'both' , which = 'minor' , labelsize = 6 )
51+ # for tick in myplt.xaxis.get_major_ticks():
52+ # tick.label.set_fontsize(8)
53+
54+ if not subplot :
55+ myplt .show ()
56+ myplt .savefig ('inputs.png' )
3257
33- def plotOutputs (self ):
58+ def plotOutputs (self , subplot = None ):
59+ myplt = subplot if subplot else plt
3460 (labels ,locs ,clusters ) = ([], [], [])
3561 (centers_sorted , out_points ) = self .getOutputPoints ()
3662 center_index_to_magnitude_map = {cx : cm for (cx ,(cm ,cloc )) in centers_sorted }
3763 for ((label , loc ), cluster ) in out_points :
3864 labels .append (label )
39- locs .append (loc )
65+ locs .append (loc [ 0 ] )
4066 clusters .append (cluster )
4167
42- colors = ['b' , 'g' , 'r' ,'y' ,'c' , 'm' ]
68+ myplt .set_title ('Output Pseudo Eigenvector' ,fontsize = 'medium' )
69+ myplt .set_xlabel ('Ordinal of Input Data' ,fontsize = 'small' )
70+ myplt .set_ylabel ('PseudoEigenvector Vti' ,fontsize = 'small' )
4371 markers = ['s' , '+' , 'x' ,'8' ,'D' , '*' ]
44- norm = plt .normalize ()
45- norm .autoscale (locs )
46- # norm.autoscale(y)
4772 for (ix , (plabel , loc , cluster )) in enumerate (zip (labels ,locs , clusters )):
48- xcolor = colors [- 1 + int (plabel / 1000 )]
73+ # for (ix, (plabel, loc, cluster)) in enumerate([(1000,0.11255703573044015,4),(1001,0.11258575254117632,4)]):
74+ xcolor = self .colors [- 1 + int (plabel / 1000 )]
4975 clusterx = center_index_to_magnitude_map [cluster ]
5076 xmarker = markers [clusterx ]
51- lines = plt .plot (ix , loc , xmarker ,markersize = 3 ,color = xcolor )
52- plt .yscale ('linear' )
53- plt .annotate (str (plabel ),xy = (ix ,loc ), xytext = (- 5 ,5 ),
54- textcoords = 'offset points' ,
55- arrowprops = dict (facecolor = xcolor , shrink = 0.01 ),
56- horizontalalignment = 'right' , verticalalignment = 'bottom' ,
57- fontsize = 6
58- )
59- # plt.plot(x, y, 'o', markersize=1,color=colors[-1 + (plabel / 1000)], label= '%s' %plabel )
60- # plt.plot(x, y)
61- # plt.plot(x, y, color='y') # , markersize=1, label= '%s' %plabel )
77+ myplt .plot (ix , loc , xmarker ,markersize = 3 ,color = xcolor )
78+ # myplt.annotate(str(plabel),xy=(ix,loc), xytext= (-5,5),
79+ # textcoords='offset points',
80+ # arrowprops=dict(facecolor=xcolor, shrink=0.01),
81+ # horizontalalignment='right', verticalalignment='bottom',
82+ # fontsize=6)
83+
84+ myplt .tick_params (axis = 'both' , which = 'major' , labelsize = 8 )
85+ myplt .tick_params (axis = 'both' , which = 'minor' , labelsize = 6 )
86+
87+ if not subplot :
88+ myplt .show ()
89+ myplt .savefig ('outputs.png' )
6290
91+ def plotInputsAndOutputs (self ):
92+ fig = plt .figure ()
93+ fig .suptitle ('Power Iteration Clustering Inputs And Outputs' ,fontsize = 'large' )
94+ ax = fig .add_subplot (211 )
95+ self .plotInputCircles (ax )
96+ ax = fig .add_subplot (212 )
97+ # x = np.linspace(-2.5,2.5,100)
98+ # ax.plot(x, np.cos(x))
99+ self .plotOutputs (ax )
100+ plt .subplots_adjust (hspace = 0.30 ) # , wspace=0.1 )
63101 plt .show ()
64- plt .savefig ('outputs .png' )
102+ plt .savefig ('inputsAndOutputs .png' )
65103
66104 def getCirclePoints (self ):
67105 fillInLabelsHere = [(1000 , (0.026055 ,0.000000 )) , (1001 , (- 0.015593 ,0.023425 )) , (1002 , (- 0.012923 ,- 0.024027 )) , (2000 , (0.300923 ,0.000000 )) , (2001 , (0.270132 ,0.148135 )) , (2002 , (0.157354 ,0.261961 )) , (2003 , (0.000000 ,0.287528 )) , (2004 , (- 0.163370 ,0.250285 )) , (2005 , (- 0.257946 ,0.153550 )) , (2006 , (- 0.290993 ,0.000000 )) , (2007 , (- 0.241891 ,- 0.148736 )) , (2008 , (- 0.152099 ,- 0.273338 )) , (2009 , (- 0.000000 ,- 0.313627 )) , (2010 , (0.140641 ,- 0.269290 )) , (2011 , (0.267766 ,- 0.145981 )) , (3000 , (1.000656 ,0.000000 )) , (3001 , (0.917339 ,0.413769 )) , (3002 , (0.664959 ,0.738677 )) , (3003 , (0.305250 ,0.931993 )) , (3004 , (- 0.103926 ,0.988312 )) , (3005 , (- 0.495637 ,0.866338 )) , (3006 , (- 0.813345 ,0.578460 )) , (3007 , (- 0.994044 ,0.205409 )) , (3008 , (- 0.970741 ,- 0.209993 )) , (3009 , (- 0.812726 ,- 0.587868 )) , (3010 , (- 0.502153 ,- 0.867390 )) , (3011 , (- 0.105587 ,- 1.000996 )) , (3012 , (0.309040 ,- 0.939486 )) , (3013 , (0.676942 ,- 0.740258 )) , (3014 , (0.922195 ,- 0.403860 )) , (4000 , (1.500370 ,0.000000 )) , (4001 , (1.455509 ,0.372520 )) , (4002 , (1.313174 ,0.724842 )) , (4003 , (1.103429 ,1.023959 )) , (4004 , (0.808768 ,1.264479 )) , (4005 , (0.463024 ,1.435827 )) , (4006 , (0.093931 ,1.489670 )) , (4007 , (- 0.282205 ,1.468860 )) , (4008 , (- 0.641969 ,1.357055 )) , (4009 , (- 0.960632 ,1.153854 )) , (4010 , (- 1.208709 ,0.881284 )) , (4011 , (- 1.398515 ,0.558539 )) , (4012 , (- 1.480977 ,0.186267 )) , (4013 , (- 1.466877 ,- 0.188276 )) , (4014 , (- 1.384225 ,- 0.551507 )) , (4015 , (- 1.210292 ,- 0.878939 )) , (4016 , (- 0.954331 ,- 1.158034 )) , (4017 , (- 0.637888 ,- 1.365072 )) , (4018 , (- 0.281502 ,- 1.485258 )) , (4019 , (0.093529 ,- 1.517232 )) , (4020 , (0.462337 ,- 1.435428 )) , (4021 , (0.802200 ,- 1.273476 )) , (4022 , (1.088346 ,- 1.022671 )) , (4023 , (1.303522 ,- 0.726381 )) , (4024 , (1.441486 ,- 0.376954 )) , (5000 , (2.006090 ,0.000000 )) , (5001 , (1.975017 ,0.312498 )) , (5002 , (1.903007 ,0.616796 )) , (5003 , (1.779725 ,0.906926 )) , (5004 , (1.615806 ,1.176478 )) , (5005 , (1.418842 ,1.412193 )) , (5006 , (1.176238 ,1.618327 )) , (5007 , (0.907240 ,1.778774 )) , (5008 , (0.616737 ,1.907389 )) , (5009 , (0.312334 ,1.972686 )) , (5010 , (0.000000 ,2.003958 )) , (5011 , (- 0.312175 ,1.978076 )) , (5012 , (- 0.617802 ,1.906119 )) , (5013 , (- 0.910539 ,1.783043 )) , (5014 , (- 1.176869 ,1.610774 )) , (5015 , (- 1.413218 ,1.413486 )) , (5016 , (- 1.612863 ,1.172439 )) , (5017 , (- 1.777011 ,0.909389 )) , (5018 , (- 1.897253 ,0.618963 )) , (5019 , (- 1.973228 ,0.312265 )) , (5020 , (- 1.997124 ,0.000000 )) , (5021 , (- 1.972173 ,- 0.312524 )) , (5022 , (- 1.904784 ,- 0.617654 )) , (5023 , (- 1.784558 ,- 0.908745 )) , (5024 , (- 1.618230 ,- 1.172448 )) , (5025 , (- 1.417072 ,- 1.417323 )) , (5026 , (- 1.173193 ,- 1.611568 )) , (5027 , (- 0.906398 ,- 1.779951 )) , (5028 , (- 0.619644 ,- 1.903364 )) , (5029 , (- 0.314077 ,- 1.973233 )) , (5030 , (- 0.000000 ,- 2.001369 )) , (5031 , (0.312326 ,- 1.985733 )) , (5032 , (0.617108 ,- 1.897669 )) , (5033 , (0.905477 ,- 1.784064 )) , (5034 , (1.178242 ,- 1.623806 )) , (5035 , (1.410244 ,- 1.418794 )) , (5036 , (1.625406 ,- 1.176519 )) , (5037 , (1.774561 ,- 0.906173 )) , (5038 , (1.897196 ,- 0.618358 )) , (5039 , (1.969360 ,- 0.311903 ))]
@@ -76,5 +114,6 @@ def getOutputPoints(self):
76114 return (centers_sorted_ix , opoints )
77115
78116if __name__ == '__main__' :
79- Plot ().plotCircles ()
80- Plot ().plotOutputs ()
117+ # Plot().plotInputCircles()
118+ # Plot().plotOutputs()
119+ Plot ().plotInputsAndOutputs ()
0 commit comments