1 import matplotlib
as mpl
2 import matplotlib
.mlab
as mlab
3 import matplotlib
.pyplot
as plt
4 import matplotlib
.axes
as axe
5 import matplotlib
.collections
as collections
9 from matplotlib
.pyplot
import *
12 FOUT
= '../map_test.png'
17 title
= "a = 1.15, w = 0.1, F = 0.00, eta1 = 1.0, eta2 = 1.5, theta = 0"
27 res
= (1440/80,900/80) # default dpi is 80
28 method
= 'direct' # mean, direct
30 ################################################################################
32 def assign_label(color
):
35 ret_label
= r
'$|v| = 0$'
37 ret_label
= r
'$|v| = -1$'
39 ret_label
= r
'$|v| = 1$'
40 if (color
== 'orange'):
41 ret_label
= r
'$|v| = 0.5$'
42 if (color
== 'green'):
43 ret_label
= r
'$|v| = -0.5$'
44 if (color
== 'black'):
45 ret_label
= r
'other rational $v$'
48 def assign_color2(colors
,xar
,yar
,clist
):
49 print "---------------------------------------------------------"
50 unique_colors
= unique(colors
)
51 ret_xcolors
= [ [] for DUMMYVAR
in range(len(clist
)) ]
52 ret_ycolors
= [ [] for DUMMYVAR
in range(len(clist
)) ]
54 assert len(xar
) == len(yar
) == len(colors
)
55 xarlen_trunc
= len(xar
)
56 while i
< xarlen_trunc
:
58 for j
in range(samples
):
59 assert i
+j
<= len(xar
)
60 #assert yar[i+j] == yar[i] and xar[i+j] == xar[i]
61 tmp
.append(colors
[i
+j
])
62 # print len(tmp), samples
63 assert len(tmp
) == samples
64 if 'green' in tmp
and 'orange' in tmp
:
65 ret_xcolors
[6].append(xar
[i
])
66 ret_ycolors
[6].append(yar
[i
])
67 elif 'blue' in tmp
and 'red' in tmp
:
68 ret_xcolors
[7].append(xar
[i
])
69 ret_ycolors
[7].append(yar
[i
])
70 elif len(unique(tmp
)) == 1 and 'grey' in tmp
:
71 ret_xcolors
[1].append(xar
[i
])
72 ret_ycolors
[1].append(yar
[i
])
73 elif len(unique(tmp
)) == 1 and 'blue' in tmp
:
74 ret_xcolors
[2].append(xar
[i
])
75 ret_ycolors
[2].append(yar
[i
])
76 elif len(unique(tmp
)) == 1 and 'green' in tmp
:
77 ret_xcolors
[3].append(xar
[i
])
78 ret_ycolors
[3].append(yar
[i
])
79 elif len(unique(tmp
)) == 1 and 'orange' in tmp
:
80 ret_xcolors
[4].append(xar
[i
])
81 ret_ycolors
[4].append(yar
[i
])
82 elif len(unique(tmp
)) == 1 and 'red' in tmp
:
83 ret_xcolors
[5].append(xar
[i
])
84 ret_ycolors
[5].append(yar
[i
])
86 ret_xcolors
[0].append(xar
[i
])
87 ret_ycolors
[0].append(yar
[i
])
91 print clist
[j
],":",len(ret_xcolors
[j
])
92 print "---------------------------------------------------------"
93 return (ret_xcolors
, ret_ycolors
)
95 def assign_color(colors
,xar
,yar
):
96 print "---------------------------------------------------------"
97 unique_colors
= unique(colors
)
98 ret_xcolors
= [ [] for DUMMYVAR
in range(len(unique_colors
)) ]
99 ret_ycolors
= [ [] for DUMMYVAR
in range(len(unique_colors
)) ]
100 for j
in range(len(unique_colors
)):
104 for i
in range(len(colors
)):
105 if (colors
[i
] == unique_colors
[j
]):
107 tmpxcolors
= ret_xcolors
[j
]
108 tmpycolors
= ret_ycolors
[j
]
110 if len(tmpxcolors
) > 0:
111 if (tmpxcolors
[-1] != xar
[i
]) or (tmpycolors
[-1] != yar
[i
]):
112 #print tmpxcolors[-1],tmpycolors[-1],"is not", xar[i],yar[i],"!"
113 ret_xcolors
[j
].append(xar
[i
])
114 ret_ycolors
[j
].append(yar
[i
])
116 ret_xcolors
[j
].append(xar
[i
])
117 ret_ycolors
[j
].append(yar
[i
])
118 lenc
= float(len(colors
))
120 print unique_colors
[j
],":",len(ret_xcolors
[j
]),k
,"(",'%.2f' % per
,"%)"
121 print "---------------------------------------------------------"
122 return (ret_xcolors
, ret_ycolors
)
124 print "reading data..."
125 r
= mlab
.csv2rec(FIN
, delimiter
='\t', comments
='#')
134 assert len(x
) == len(y
) == len(vx
) == len(vy
)
137 xmin
= np
.min(unique(x
))
138 xmax
= np
.max(unique(x
))
139 ymin
= np
.min(unique(y
))
140 ymax
= np
.max(unique(y
))
142 # assumes that the step distance doesn't change over the course of time
144 print "size of xstep:", xstep
145 print "size of ystep:", ystep
146 print "aspect ratio:",rat
148 print "different values of vx:"
149 print unique(vx
),"(",len(vx
),"total)"
151 print "different values of vy:"
152 print unique(vy
),"(",len(vy
),"total)"
154 # needed for assign_color2
156 'black', # 0 everything else
159 'green', # 3 v = -0.5
160 'orange', # 4 v = 0.5
162 'teal', # 6 v = -0.5 && v = 0.5
163 'purple' # 7 v = -1.0 && v = 1.0
167 r
'other rational $v$', # 0 black
169 r
'$v = -1$', # 2 blue
170 r
'$v = -0.5$', # 3 green
171 r
'$v = 0.5$', # 4 orange
172 r
'$v = 1.0$', # 5 red
173 r
'$v = \pm 0.5$', # 6 teal
174 r
'$v = \pm 1.0$' # 7 purple
181 xlim
= (xpadmin
, xpadmax
) # small padding between plot and
182 ylim
= (ypadmin
, ypadmax
) # axis so they don't overlap
183 xticks
= np
.arange(xmin
, xmax
+xpad
, xtfreq
)
184 yticks
= np
.arange(ymin
, ymax
+ypad
, ytfreq
)
187 fig
= plt
.figure(figsize
=res
)
188 #fig.suptitle(title, size=labelsize)
192 rect1
= [0.1, 0.1, c
, 0.9]
193 rect2
= [c
+0.1, 0.1, c
, 0.9]
195 ax1
= fig
.add_axes(rect1
, aspect
=rat
)
196 ax2
= fig
.add_axes(rect2
, aspect
=rat
)
198 if (method
== 'mean'):
200 print "assigning colors...."
201 xcolors_x
,xcolors_y
= assign_color(x_color
,x
,y
)
202 ycolors_x
,ycolors_y
= assign_color(y_color
,x
,y
)
206 for k
in range(len(unique(x_color
))):
207 x_xtli
= xcolors_x
[k
]
208 x_ytli
= xcolors_y
[k
]
209 labelx
= assign_label(unique(x_color
)[k
])
210 ax1
.scatter(x_xtli
, x_ytli
, marker
='s', lw
=0, s
=ms
, alpha
=0.5,
211 c
= unique(x_color
)[k
], label
=labelx
,
214 for k
in range(len(unique(y_color
))):
215 y_xtli
= ycolors_x
[k
]
216 y_ytli
= ycolors_y
[k
]
217 labely
= assign_label(unique(y_color
)[k
])
218 ax2
.scatter(y_xtli
, y_ytli
, marker
='s', lw
=0, s
=ms
, alpha
=0.5,
219 c
= unique(y_color
)[k
], label
=labely
,
224 elif (method
== 'direct'):
226 print "assigning colors..."
227 xcolors_x
,xcolors_y
= assign_color2(x_color
,x
,y
,color_list
)
228 ycolors_x
,ycolors_y
= assign_color2(y_color
,x
,y
,color_list
)
232 # print i, xcolors_x[i],xcolors_y[i];
235 for k
in range(len(xcolors_x
)):
236 if len(xcolors_x
[k
]) > 0:
237 x_xtli
= xcolors_x
[k
]
238 x_ytli
= xcolors_y
[k
]
239 ax1
.scatter(x_xtli
, x_ytli
, marker
='s', lw
=0,
240 s
=ms
, alpha
=1, c
=color_list
[k
],
243 for k
in range(len(ycolors_x
)):
244 if len(ycolors_x
[k
]) > 0:
245 y_xtli
= ycolors_x
[k
]
246 y_ytli
= ycolors_y
[k
]
247 ax2
.scatter(y_xtli
, y_ytli
, marker
='s', lw
=0,
248 s
=ms
, alpha
=1, c
=color_list
[k
],
253 print "fatal error: specify a valid method"
255 leg1
= ax1
.legend(bbox_to_anchor
=(1.05, 1), loc
=2, shadow
=True,
256 fancybox
=True, scatterpoints
=1, markerscale
=1,
258 leg2
= ax2
.legend(bbox_to_anchor
=(1.05, 1), loc
=2, shadow
=True,
259 fancybox
=True, scatterpoints
=1, markerscale
=1,
261 for t
in leg1
.get_texts():
262 t
.set_fontsize('small')
263 for t
in leg2
.get_texts():
264 t
.set_fontsize('small')
266 ax1
.set_title(r
'$v_x$', size
=labelsize
)
269 ax1
.set_xlabel(xlabel
, size
=labelsize
)
270 ax1
.set_ylabel(ylabel
, size
=labelsize
)
271 ax1
.set_xticks(xticks
, minor
=False)
272 ax1
.set_yticks(yticks
, minor
=False)
273 ax1
.set_xticklabels(ax1
.get_xticks(), size
=ticksize
)
274 ax1
.set_yticklabels(ax1
.get_yticks(), size
=ticksize
)
276 ax2
.set_title(r
'$v_y$', size
=labelsize
)
279 ax2
.set_xlabel(xlabel
, size
=labelsize
)
280 ax2
.set_ylabel('', size
=labelsize
)
281 ax2
.set_xticks(xticks
, minor
=False)
282 ax2
.set_yticks(yticks
, minor
=False)
283 ax2
.set_xticklabels(ax2
.get_xticks(), size
=ticksize
)
284 ax2
.set_yticklabels('', size
=ticksize
)
286 leg1
.get_frame().set_alpha(0.75)
287 leg2
.get_frame().set_alpha(0.75)
289 plt
.subplots_adjust(hspace
=0)
290 print "flushing into a file..."