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_alphaltheta45f01.png'
17 title
= "a = 1.15, w = 0.1, F = 0.00, eta1 = 1.0, eta2 = 1.5, theta = 0"
22 res
= (1440/80,900/80) # default dpi is 80
23 method
= 'direct' # mean, direct
25 ################################################################################
27 def assign_label(color
):
30 ret_label
= r
'$|v| = 0$'
32 ret_label
= r
'$|v| = -1$'
34 ret_label
= r
'$|v| = 1$'
35 if (color
== 'orange'):
36 ret_label
= r
'$|v| = 0.5$'
37 if (color
== 'green'):
38 ret_label
= r
'$|v| = -0.5$'
39 if (color
== 'black'):
40 ret_label
= r
'other rational $v$'
43 def assign_color2(colors
,xar
,yar
):
55 #print "---------------------------------------------------------"
56 unique_colors
= unique(colors
)
57 ret_xcolors
= [ [] for DUMMYVAR
in range(8) ]
58 ret_ycolors
= [ [] for DUMMYVAR
in range(8) ]
60 assert len(xar
) == len(yar
) == len(colors
)
61 xarlen_trunc
= len(xar
)
62 while (i
< xarlen_trunc
):
66 for j
in range(samples
):
68 assert i
+j
<= len(xar
)
69 assert yar
[i
+j
] == yar
[i
] and xar
[i
+j
] == xar
[i
]
70 tmp
.append(colors
[i
+j
])
71 assert len(tmp
) == samples
72 if 'green' in tmp
and 'orange' in tmp
:
73 ret_xcolors
[6].append(xar
[i
])
74 ret_ycolors
[6].append(yar
[i
])
75 elif 'blue' in tmp
and 'red' in tmp
:
76 ret_xcolors
[7].append(xar
[i
])
77 ret_ycolors
[7].append(yar
[i
])
78 elif len(unique(tmp
)) == 1 and 'grey' in tmp
:
79 ret_xcolors
[1].append(xar
[i
])
80 ret_ycolors
[1].append(yar
[i
])
81 elif len(unique(tmp
)) == 1 and 'blue' in tmp
:
82 ret_xcolors
[2].append(xar
[i
])
83 ret_ycolors
[2].append(yar
[i
])
84 elif len(unique(tmp
)) == 1 and 'green' in tmp
:
85 ret_xcolors
[3].append(xar
[i
])
86 ret_ycolors
[3].append(yar
[i
])
87 elif len(unique(tmp
)) == 1 and 'orange' in tmp
:
88 ret_xcolors
[4].append(xar
[i
])
89 ret_ycolors
[4].append(yar
[i
])
90 elif len(unique(tmp
)) == 1 and 'red' in tmp
:
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
])
98 #print "---------------------------------------------------------"
99 return (ret_xcolors
, ret_ycolors
)
101 def assign_color(colors
,xar
,yar
):
102 print "---------------------------------------------------------"
103 unique_colors
= unique(colors
)
104 ret_xcolors
= [ [] for DUMMYVAR
in range(len(unique_colors
)) ]
105 ret_ycolors
= [ [] for DUMMYVAR
in range(len(unique_colors
)) ]
106 for j
in range(len(unique_colors
)):
110 for i
in range(len(colors
)):
111 if (colors
[i
] == unique_colors
[j
]):
113 tmpxcolors
= ret_xcolors
[j
]
114 tmpycolors
= ret_ycolors
[j
]
116 if len(tmpxcolors
) > 0:
117 if (tmpxcolors
[-1] != xar
[i
]) or (tmpycolors
[-1] != yar
[i
]):
118 #print tmpxcolors[-1],tmpycolors[-1],"is not", xar[i],yar[i],"!"
119 ret_xcolors
[j
].append(xar
[i
])
120 ret_ycolors
[j
].append(yar
[i
])
122 ret_xcolors
[j
].append(xar
[i
])
123 ret_ycolors
[j
].append(yar
[i
])
124 lenc
= float(len(colors
))
126 print unique_colors
[j
],":",len(ret_xcolors
[j
]),k
,"(",'%.2f' % per
,"%)"
127 print "---------------------------------------------------------"
128 return (ret_xcolors
, ret_ycolors
)
130 r
= mlab
.csv2rec(FIN
, delimiter
='\t', comments
='#')
139 assert len(x
) == len(y
) == len(vx
) == len(vy
)
141 xmin
= np
.min(unique(x
))
142 xmax
= np
.max(unique(x
))
143 ymin
= np
.min(unique(y
))
144 ymax
= np
.max(unique(y
))
146 # assumes that the step distance doesn't change over the course of time
150 print "size of xstep:", xstep
151 print "size of ystep:", ystep
152 print "aspect ratio:",rat
154 print "different values of vx:"
155 print unique(vx
),"(",len(vx
),"total)"
157 print "different values of vy:"
158 print unique(vy
),"(",len(vy
),"total)"
160 # needed for assign_color2
162 'black', # 0 everything else
165 'green', # 3 v = -0.5
166 'orange', # 4 v = 0.5
168 'teal', # 6 v = -0.5 && v = 0.5
169 'purple' # 7 v = -1.0 && v = 1.0
173 r
'other rational $v$', # 0 black
175 r
'$v| = -1$', # 2 blue
176 r
'$v = -0.5$', # 3 green
177 r
'$v = 0.5$', # 4 orange
178 r
'$v = 1.0$', # 5 red
179 r
'$v = \pm 0.5$', # 6 teal
180 r
'$v = \pm 1.0$' # 7 purple
187 xlim
= (xpadmin
, xpadmax
) # small padding between plot and
188 ylim
= (ypadmin
, ypadmax
) # axis so they don't overlap
189 xticks
= np
.linspace(xmin
, xmax
, tfreq
)
190 yticks
= np
.linspace(ymin
, ymax
+ystep
, tfreq
)
193 fig
= plt
.figure(figsize
=res
)
194 fig
.suptitle(title
, size
=labelsize
)
198 rect1
= [0.1, 0.1, c
, 0.9]
199 rect2
= [c
+0.1, 0.1, c
, 0.9]
201 ax1
= fig
.add_axes(rect1
, aspect
=rat
)
202 ax2
= fig
.add_axes(rect2
, aspect
=rat
)
204 if (method
== 'mean'):
206 xcolors_x
,xcolors_y
= assign_color(x_color
,x
,y
)
207 ycolors_x
,ycolors_y
= assign_color(y_color
,x
,y
)
209 for k
in range(len(unique(x_color
))):
210 x_xtli
= xcolors_x
[k
]
211 x_ytli
= xcolors_y
[k
]
212 labelx
= assign_label(unique(x_color
)[k
])
213 ax1
.scatter(x_xtli
, x_ytli
, marker
='s', lw
=0, s
=ms
, alpha
=0.5,
214 c
= unique(x_color
)[k
], label
=labelx
)
216 for k
in range(len(unique(y_color
))):
217 y_xtli
= ycolors_x
[k
]
218 y_ytli
= ycolors_y
[k
]
219 labely
= assign_label(unique(y_color
)[k
])
220 ax2
.scatter(y_xtli
, y_ytli
, marker
='s', lw
=0, s
=ms
, alpha
=0.5,
221 c
= unique(y_color
)[k
], label
=labely
)
223 elif (method
== 'direct'):
225 xcolors_x
,xcolors_y
= assign_color2(x_color
,x
,y
)
226 ycolors_x
,ycolors_y
= assign_color2(y_color
,x
,y
)
228 for k
in range(len(color_list
)):
229 x_xtli
= xcolors_x
[k
]
230 x_ytli
= xcolors_y
[k
]
231 #labelx = assign_label(color_list)[k]
232 ax1
.scatter(x_xtli
, x_ytli
, marker
='s', lw
=0, s
=ms
, alpha
=0.5,
233 c
= color_list
[k
], label
=label_list
[k
])
235 for k
in range(len(color_list
)):
236 y_xtli
= ycolors_x
[k
]
237 y_ytli
= ycolors_y
[k
]
238 #labely = assign_label(color_list[k])
239 ax2
.scatter(y_xtli
, y_ytli
, marker
='s', lw
=0, s
=ms
, alpha
=0.5,
240 c
= color_list
[k
], label
=label_list
[k
])
243 print "fatal error: specify a valid method"
245 leg1
= ax1
.legend(loc
=0, shadow
=True, fancybox
=True, scatterpoints
=1,
247 leg2
= ax2
.legend(loc
=0, shadow
=True, fancybox
=True, scatterpoints
=1,
249 for t
in leg1
.get_texts():
250 t
.set_fontsize('small')
251 for t
in leg2
.get_texts():
252 t
.set_fontsize('small')
254 ax1
.set_title(r
'$v_x$', size
=labelsize
)
257 ax1
.set_xlabel(xlabel
, size
=labelsize
)
258 ax1
.set_ylabel(ylabel
, size
=labelsize
)
259 ax1
.set_xticks(xticks
, minor
=False)
260 ax1
.set_yticks(yticks
, minor
=False)
261 ax1
.set_xticklabels(ax1
.get_xticks(), size
=ticksize
)
262 ax1
.set_yticklabels(ax1
.get_yticks(), size
=ticksize
)
264 ax2
.set_title(r
'$v_y$', size
=labelsize
)
267 ax2
.set_xlabel(xlabel
, size
=labelsize
)
268 ax2
.set_ylabel('', size
=labelsize
)
269 ax2
.set_xticks(xticks
, minor
=False)
270 ax2
.set_yticks(yticks
, minor
=False)
271 ax2
.set_xticklabels(ax2
.get_xticks(), size
=ticksize
)
272 ax2
.set_yticklabels('', size
=ticksize
)
274 leg1
.get_frame().set_alpha(0.75)
275 leg2
.get_frame().set_alpha(0.75)
277 plt
.subplots_adjust(hspace
=0)