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 col
9 from matplotlib
.pyplot
import *
11 FIN
= '../data/dual_bif_alpha_l_55_65_1_4_f0005.dat'
17 title
= "a = 1.15, w = 0.1, F = 0.00, eta1 = 1.0, eta2 = 1.5, theta = 0"
28 res
= (1024/80,768/80) # default dpi is 80
29 method
= 'direct' # mean, direct
34 ################################################################################
36 def assign_label(color
):
39 ret_label
= r
'$|v| = 0$'
41 ret_label
= r
'$|v| = -1$'
43 ret_label
= r
'$|v| = 1$'
44 if (color
== 'orange'):
45 ret_label
= r
'$|v| = 0.5$'
46 if (color
== 'green'):
47 ret_label
= r
'$|v| = -0.5$'
48 if (color
== 'black'):
49 ret_label
= r
'other rational $v$'
51 ret_label
= r
'$v < 0$'
52 if (color
== 'magenta'):
53 ret_label
= r
'$v > 0$'
56 def assign_color2(colors
,xar
,yar
,vel
,clist
):
57 print "---------------------------------------------------------"
58 unique_colors
= unique(colors
)
59 #print range(len(clist))
60 ret_xcolors
= [ [] for DUMMYVAR
in range(len(clist
)) ]
61 ret_ycolors
= [ [] for DUMMYVAR
in range(len(clist
)) ]
63 assert len(xar
) == len(yar
) == len(colors
)
64 xarlen_trunc
= len(xar
)
65 while i
< xarlen_trunc
:
68 for j
in range(samples
):
69 assert i
+j
<= len(xar
)
70 #assert yar[i+j] == yar[i] and xar[i+j] == xar[i]
71 tmp
.append(colors
[i
+j
])
73 # print len(tmp), samples
74 assert len(tmp
) == samples
75 ccount
= len(unique(tmp
))
76 if ccount
== 2 and 'green' in tmp
and 'orange' in tmp
:
77 ret_xcolors
[6].append(xar
[i
])
78 ret_ycolors
[6].append(yar
[i
])
79 elif ccount
== 2 and 'blue' in tmp
and 'red' in tmp
:
80 ret_xcolors
[7].append(xar
[i
])
81 ret_ycolors
[7].append(yar
[i
])
82 elif ccount
== 2 and 'blue' in tmp
and 'black' in tmp
:
83 if tmp
.count('blue') >= samples
/2:
84 ret_xcolors
[2].append(xar
[i
])
85 ret_ycolors
[2].append(yar
[i
])
87 ret_xcolors
[0].append(xar
[i
])
88 ret_ycolors
[0].append(yar
[i
])
89 elif ccount
== 2 and 'red' in tmp
and 'black' in tmp
:
90 if tmp
.count('red') >= samples
/2:
91 ret_xcolors
[5].append(xar
[i
])
92 ret_ycolors
[5].append(yar
[i
])
94 ret_xcolors
[0].append(xar
[i
])
95 ret_ycolors
[0].append(yar
[i
])
96 elif ccount
== 2 and 'green' in tmp
and 'black' in tmp
:
97 if tmp
.count('green') >= samples
/2:
98 ret_xcolors
[3].append(xar
[i
])
99 ret_ycolors
[3].append(yar
[i
])
101 ret_xcolors
[0].append(xar
[i
])
102 ret_ycolors
[0].append(yar
[i
])
103 elif ccount
== 2 and 'orange' in tmp
and 'black' in tmp
:
104 if tmp
.count('orange') >= samples
/2:
105 ret_xcolors
[4].append(xar
[i
])
106 ret_ycolors
[4].append(yar
[i
])
108 ret_xcolors
[0].append(xar
[i
])
109 ret_ycolors
[0].append(yar
[i
])
110 elif ccount
== 3 and 'green' in tmp
and 'orange' in tmp
and 'grey':
111 ret_xcolors
[6].append(xar
[i
])
112 ret_ycolors
[6].append(yar
[i
])
113 elif ccount
== 3 and 'blue' in tmp
and 'red' in tmp
and 'grey':
114 ret_xcolors
[7].append(xar
[i
])
115 ret_ycolors
[7].append(yar
[i
])
116 elif ccount
== 4 and 'blue' in tmp
and 'red' in tmp
and 'green' in tmp
and 'orange' in tmp
:
118 ret_xcolors
[11].append(xar
[i
])
119 ret_ycolors
[11].append(yar
[i
])
120 elif ccount
== 4 and 'green' in tmp
and 'orange' in tmp
and 'grey' in tmp
and 'black' in tmp
:
121 ret_xcolors
[6].append(xar
[i
])
122 ret_ycolors
[6].append(yar
[i
])
123 elif ccount
== 4 and 'blue' in tmp
and 'red' in tmp
and 'grey' in tmp
and 'black' in tmp
:
124 ret_xcolors
[7].append(xar
[i
])
125 ret_ycolors
[7].append(yar
[i
])
126 elif ccount
== 1 and 'grey' in tmp
:
127 ret_xcolors
[1].append(xar
[i
])
128 ret_ycolors
[1].append(yar
[i
])
129 elif ccount
== 1 and 'blue' in tmp
:
130 ret_xcolors
[2].append(xar
[i
])
131 ret_ycolors
[2].append(yar
[i
])
132 elif ccount
== 1 and 'green' in tmp
:
133 ret_xcolors
[3].append(xar
[i
])
134 ret_ycolors
[3].append(yar
[i
])
135 elif ccount
== 1 and 'orange' in tmp
:
136 ret_xcolors
[4].append(xar
[i
])
137 ret_ycolors
[4].append(yar
[i
])
138 elif ccount
== 1 and 'red' in tmp
:
139 ret_xcolors
[5].append(xar
[i
])
140 ret_ycolors
[5].append(yar
[i
])
141 elif len(unique(tmpv
)) >= samples
:
143 ret_xcolors
[0].append(xar
[i
])
144 ret_ycolors
[0].append(yar
[i
])
145 elif ccount
== 1 and 'black' in tmp
:
146 ret_xcolors
[0].append(xar
[i
])
147 ret_ycolors
[0].append(yar
[i
])
151 ret_xcolors
[0].append(xar
[i
])
152 ret_ycolors
[0].append(yar
[i
])
154 #print "increment:",i
155 for j
in range(len(clist
)):
156 print clist
[j
],":",len(ret_xcolors
[j
])
157 #print "unmatched velocities:"
158 #print ret_xcolors[13], ret_ycolors[13]
159 print "---------------------------------------------------------"
160 return (ret_xcolors
, ret_ycolors
)
162 def assign_color(colors
,xar
,yar
):
163 print "---------------------------------------------------------"
164 unique_colors
= unique(colors
)
165 ret_xcolors
= [ [] for DUMMYVAR
in range(len(unique_colors
)) ]
166 ret_ycolors
= [ [] for DUMMYVAR
in range(len(unique_colors
)) ]
167 for j
in range(len(unique_colors
)):
171 for i
in range(len(colors
)):
172 if (colors
[i
] == unique_colors
[j
]):
174 tmpxcolors
= ret_xcolors
[j
]
175 tmpycolors
= ret_ycolors
[j
]
177 if len(tmpxcolors
) > 0:
178 if (tmpxcolors
[-1] != xar
[i
]) or (tmpycolors
[-1] != yar
[i
]):
179 #print tmpxcolors[-1],tmpycolors[-1],"is not", xar[i],yar[i],"!"
180 ret_xcolors
[j
].append(xar
[i
])
181 ret_ycolors
[j
].append(yar
[i
])
183 ret_xcolors
[j
].append(xar
[i
])
184 ret_ycolors
[j
].append(yar
[i
])
185 lenc
= float(len(colors
))
187 print unique_colors
[j
],":",len(ret_xcolors
[j
]),k
,"(",'%.2f' % per
,"%)"
188 print "---------------------------------------------------------"
189 return (ret_xcolors
, ret_ycolors
)
191 print "reading data..."
192 r
= mlab
.csv2rec(FIN
, delimiter
='\t', comments
='#')
201 assert len(x
) == len(y
) == len(vx
) == len(vy
)
204 xmin
= np
.min(unique(x
))
205 xmax
= np
.max(unique(x
))
206 ymin
= np
.min(unique(y
))
207 ymax
= np
.max(unique(y
))
209 # assumes that the step distance doesn't change over the course of time
211 print "size of xstep:", xstep
212 print "size of ystep:", ystep
213 print "aspect ratio:",rat
215 print "different values of vx:"
216 print unique(vx
),"(",len(vx
),"total)"
218 print "different values of vy:"
219 print unique(vy
),"(",len(vy
),"total)"
221 # needed for assign_color2
223 'black', # 0 everything else
226 'green', # 3 v = -0.5
227 'orange', # 4 v = 0.5
229 'khaki', # 6 v = -0.5 && v = 0.5
230 'purple', # 7 v = -1.0 && v = 1.0
231 'white', # 8 not understood
232 'darkgoldenrod',# 9 v = +/- 0.5 & 0
233 'mediumpurple', # 10 v = +/- 1 1 & -0
234 'brown', # 11 v = +/1 1 & +/- 0.5
238 r
'other rational $v$', # 0 black
240 r
'$v = -1$', # 2 blue
241 r
'$v = -\frac{1}{2}$', # 3 green
242 r
'$v = \frac{1}{2}$', # 4 orange
244 r
'$v = \pm \frac{1}{2}$', # 6 brown
245 r
'$v = \pm 1$', # 7 purple
247 r
'$v = \pm \frac{1}{2},$ other',# 9 darkgoldenrod
248 r
'$v = \pm 1,$ other ', # 10 mediumpurple
249 r
'$v = \pm 1,\pm \frac{1}{2}$', # 11 brown
256 xlim
= (xpadmin
, xpadmax
) # small padding between plot and
257 ylim
= (ypadmin
, ypadmax
) # axis so they don't overlap
258 xticks
= np
.arange(xmin
, xmax
+xpad
, xtfreq
)
259 yticks
= np
.arange(ymin
, ymax
+ypad
, ytfreq
)
262 fig
= plt
.figure() #(figsize=res)
263 #fig.suptitle(title, size=labelsize)
267 rect1
= [0.1, 0.1, c
, 0.9]
268 rect2
= [c
+0.1, 0.1, c
, 0.9]
271 ax1
= fig
.add_subplot(121, aspect
=rat
)
272 ax2
= fig
.add_subplot(122, aspect
=rat
)
274 ax1
= fig
.add_subplot(111, aspect
=rat
)
276 if (method
== 'mean'):
278 print "assigning colors...."
279 xcolors_x
,xcolors_y
= assign_color(x_color
,x
,y
)
280 ycolors_x
,ycolors_y
= assign_color(y_color
,x
,y
)
284 for k
in range(len(unique(x_color
))):
285 x_xtli
= xcolors_x
[k
]
286 x_ytli
= xcolors_y
[k
]
287 labelx
= assign_label(unique(x_color
)[k
])
288 ax1
.scatter(x_xtli
, x_ytli
, marker
='s', lw
=0, s
=ms
, alpha
=0.5,
289 c
= unique(x_color
)[k
], label
=labelx
,
292 for k
in range(len(unique(y_color
))):
293 y_xtli
= ycolors_x
[k
]
294 y_ytli
= ycolors_y
[k
]
295 labely
= assign_label(unique(y_color
)[k
])
296 ax2
.scatter(y_xtli
, y_ytli
, marker
='s', lw
=0,
299 label
=labely
, edgecolor
='none')
303 elif (method
== 'direct'):
305 print "assigning colors..."
306 xcolors_x
,xcolors_y
= assign_color2(x_color
,x
,y
,vx
,color_list
)
307 ycolors_x
,ycolors_y
= assign_color2(y_color
,x
,y
,vy
,color_list
)
311 # print i, xcolors_x[i],xcolors_y[i];
314 for k
in range(len(xcolors_x
)):
315 if len(xcolors_x
[k
]) > 0:
316 x_xtli
= xcolors_x
[k
]
317 x_ytli
= xcolors_y
[k
]
318 ax1
.scatter(x_xtli
, x_ytli
, marker
='s', lw
=0,
320 s
=ms
, alpha
=1, c
=color_list
[k
],
324 for k
in range(len(ycolors_x
)):
325 if len(ycolors_x
[k
]) > 0:
326 y_xtli
= ycolors_x
[k
]
327 y_ytli
= ycolors_y
[k
]
328 ax2
.scatter(y_xtli
, y_ytli
, marker
='s',
335 print "fatal error: specify a valid method"
337 leg1
= ax1
.legend(loc
=0, shadow
=True,
338 fancybox
=True, scatterpoints
=1, markerscale
=1,
340 for t
in leg1
.get_texts():
341 t
.set_fontsize('small')
344 leg2
= ax2
.legend(loc
=2, shadow
=True,
345 fancybox
=True, scatterpoints
=1, markerscale
=1,
347 for t
in leg2
.get_texts():
348 t
.set_fontsize('small')
351 ax1
.set_title(r
'$v_x$', size
=labelsize
)
354 ax1
.set_xlabel(xlabel
, size
=labelsize
)
355 ax1
.set_ylabel(ylabel
, size
=labelsize
)
356 ax1
.set_xticks(xticks
, minor
=False)
357 ax1
.set_yticks(yticks
, minor
=False)
358 ax1
.set_xticklabels(ax1
.get_xticks(), size
=ticksize
)
359 ax1
.set_yticklabels(ax1
.get_yticks(), size
=ticksize
)
362 ax2
.set_title(r
'$v_y$', size
=labelsize
)
365 ax2
.set_xlabel(xlabel
, size
=labelsize
)
366 ax2
.set_ylabel('', size
=labelsize
)
367 ax2
.set_xticks(xticks
, minor
=False)
368 ax2
.set_yticks(yticks
, minor
=False)
369 ax2
.set_xticklabels(ax2
.get_xticks(), size
=ticksize
)
370 ax2
.set_yticklabels('', size
=ticksize
)
372 if (has_col
is True):
373 s1
= np
.arange(54.5,66,0.5)
374 collection
= col
.BrokenBarHCollection
.span_where(s1
, ymin
=0.95, ymax
=4.05,
375 where
=s1
>54, facecolor
='None', edgecolor
='red')
376 ax1
.add_collection(collection
)
379 leg1
.get_frame().set_alpha(0.75)
382 leg2
.get_frame().set_alpha(0.75)
385 plt
.subplots_adjust(hspace
=0)
386 print "flushing into a file..."