2 # -*- coding: iso-8859-1 -*-
4 import matplotlib
as mpl
6 import matplotlib
.cm
as cm
7 import matplotlib
.mlab
as mlab
8 import matplotlib
.pyplot
as plt
9 import matplotlib
.patches
as patch
10 import matplotlib
.colors
as col
12 FOUT
= '../latex2/images/dimer_sympartner.png'
13 FCOF
= '../rk_out.dat'
14 FP1
= '../rk_point1.dat'
15 FP2
= '../rk_point2.dat'
16 FVEL
= "../rk_velo.dat"
21 evry
= 1 # plot periodicity, don't set < 10 (bug)
22 offx
= -98 # offset of (x,y) in L
26 acangle
= 58 # angle of ac drive
27 dcangle
= 0 # angle of dc bias
28 sperx
= 4 # spacial periodicity
30 pad
= 0.01 # small padding so the ticks get drawn correctly...
32 res
= (1440/80,900/80) # default dpi is 80
33 cmap
= cm
.gray_r
# colormap
34 shader
= False # applies ultra cool shadows to the map!
38 cblabel
= r
'$\cos(x)\cos(y)+\cos(x)+\cos(y)$'
46 show_annotations
= False
48 title
= 'F = 0.1, alpha = 83, l = 3.0, a = 1.5, eta1 = 1.0, eta2 = 1.5, theta = 0'
50 ################################################################################
52 print "reading data..."
54 data_cof
= mlab
.csv2rec(FCOF
, delimiter
='\t', comments
='#')
55 data_p1
= mlab
.csv2rec(FP1
, delimiter
='\t', comments
='#')
56 data_p2
= mlab
.csv2rec(FP2
, delimiter
='\t', comments
='#')
57 data_v
= mlab
.csv2rec(FVEL
, delimiter
='\t', comments
='#')
66 pxdiff
= data_p2
.x
- data_p1
.x
67 pydiff
= data_p2
.y
- data_p1
.y
78 tcx
= [0.59,0.65,0.65,0.57,0.52,0.39]
79 tcy
= [0.4,0.6,0.83,0.6,0.51,0.4]
80 tl
= ["1","2","3","4","5","6"]
83 trunc_cofx
= cofx
[fromt
*tau
:tot
*tau
:evry
].tolist()
84 trunc_cofy
= cofy
[fromt
*tau
:tot
*tau
:evry
].tolist()
85 trunc_p1x
= p1x
[fromt
*tau
:tot
*tau
:evry
].tolist()
86 trunc_p2x
= p2x
[fromt
*tau
:tot
*tau
:evry
].tolist()
87 trunc_p2y
= p2y
[fromt
*tau
:tot
*tau
:evry
].tolist()
88 trunc_p1y
= p1y
[fromt
*tau
:tot
*tau
:evry
].tolist()
89 trunc_pxdiff
= pxdiff
[fromt
*tau
:tot
*tau
:evry
].tolist()
90 trunc_pydiff
= pydiff
[fromt
*tau
:tot
*tau
:evry
].tolist()
91 trunc_t
= t
[fromt
*tau
:tot
*tau
:evry
].tolist()
92 trunc_vx
= vx
[fromt
*tau
:tot
*tau
:evry
].tolist()
93 trunc_vy
= vy
[fromt
*tau
:tot
*tau
:evry
].tolist()
95 def uniquify(seq
, idfun
=None):
98 def idfun(x
): return x
103 # in old Python versions:
104 # # if seen.has_key(marker)
106 if marker
in seen
: continue
115 trunc_pxdiff_eff
= []
116 trunc_pydiff_eff
= []
120 for i
in range(len(trunc_cofx
)):
121 assert len(trunc_cofx
) == len(trunc_p1x
)
122 #print i, len(trunc_p1x_eff), len(trunc_cofx)
123 vel
= np
.sqrt(pow(trunc_vx
[i
],2)+pow(trunc_vy
[i
],2))
124 p1
= abs(np
.sqrt(pow(trunc_p1x
[i
],2)+pow(trunc_p1y
[i
],2))-np
.sqrt(pow(trunc_p1x
[i
-1],2)+pow(trunc_p1y
[i
-1],2)))
125 p2
= abs(np
.sqrt(pow(trunc_p2x
[i
],2)+pow(trunc_p2y
[i
],2))-np
.sqrt(pow(trunc_p2x
[i
-1],2)+pow(trunc_p2y
[i
-1],2)))
127 if (p1
< thresh
) and (p2
< thresh
):
128 trunc_cofx
[i
] = trunc_cofx
[i
-1]
129 trunc_cofy
[i
] = trunc_cofy
[i
-1]
130 trunc_p1x
[i
] = trunc_p1x
[i
-1]
131 trunc_p2x
[i
] = trunc_p2x
[i
-1]
132 trunc_p1y
[i
] = trunc_p1y
[i
-1]
133 trunc_p2y
[i
] = trunc_p2y
[i
-1]
134 trunc_pxdiff
[i
] = trunc_pxdiff
[i
-1]
135 trunc_pydiff
[i
] = trunc_pydiff
[i
-1]
136 trunc_vx
[i
] = trunc_vx
[i
-1]
137 trunc_vy
[i
] = trunc_vy
[i
-1]
139 print "velocity:",vel
, "dp1:", p1
, "dp2:", p2
141 set_p1x
= trunc_p1x
#uniquify(trunc_p1x)
142 set_p1y
= trunc_p1y
#uniquify(trunc_p1y)
143 set_p2x
= trunc_p2x
#uniquify(trunc_p2x)
144 set_p2y
= trunc_p2y
#uniquify(trunc_p2y)
145 set_pxdiff
= trunc_pxdiff
#uniquify(trunc_pxdiff)
146 set_pydiff
= trunc_pydiff
#uniquify(trunc_pydiff)
147 set_vx
= trunc_vx
#uniquify(trunc_vx)
148 set_vy
= trunc_vy
#uniquify(trunc_vy)
149 set_cofx
= trunc_cofx
150 set_cofy
= trunc_cofy
153 print len(set_cofx
), len(set_cofy
)
155 xmax
= np
.ceil(max(trunc_cofx
)/L
)
156 xmin
= np
.ceil(min(trunc_cofx
)/L
)
157 ymax
= np
.ceil(max(trunc_cofy
)/L
)
158 ymin
= np
.ceil(min(trunc_cofy
)/L
)
160 xdiff
= np
.ceil(abs(max(trunc_cofx
)-min(trunc_cofx
))/L
)
161 ydiff
= np
.ceil(abs(max(trunc_cofy
)-min(trunc_cofy
))/L
)
167 #print xdiff-(xdiff-sper)
170 limx_min
= (xmin
+2)*L
171 limx_max
= (xmin
+2+sperx
)*L
173 limx_min
= (xmax
-2-sperx
)*L
174 limx_max
= (xmax
-2)*L
176 limy_min
= (ymin
-2)*L
177 limy_max
= (ymin
-2+spery
)*L
179 limy_min
= (ymax
-spery
)*L
182 #print (limx_max-limx_min)/L
184 print "x:","(",limx_min
,",",limx_max
,")"
185 print "y:","(",limy_min
,",",limy_max
,")"
187 xticks
= np
.arange(limx_min
,limx_max
+pad
,L
)
188 yticks
= np
.arange(limy_min
,limy_max
+pad
,L
)
189 xlim
= (limx_min
-pad
,limx_max
+pad
)
190 ylim
= (limy_min
-pad
,limy_max
+pad
)
191 tlabel
= ("-2L","-L","0","L","2L")
193 print "generating basemap..."
195 x
= np
.arange(limx_min
,limx_max
, delta
)
196 y
= np
.arange(limy_min
,limy_max
, delta
)
197 X
,Y
= np
.meshgrid(x
, y
)
198 Z
= np
.cos(X
)*np
.cos(Y
)+np
.cos(X
)+np
.cos(Y
)
204 fig
= plt
.figure() #(figsize=res)
206 ax
= fig
.add_subplot(111)
209 print "applying lightsource..."
210 ls
= col
.LightSource(azdeg
=0,altdeg
=90)
211 rgb
= ls
.shade(Z
,cmap
)
213 print "plotting basemap..."
214 pot
= plt
.imshow(rgb
, extent
=[limx_min
,limx_max
,limy_min
,limy_max
])
217 print "plotting basemap..."
218 pot
= plt
.pcolormesh(X
,Y
,Z
, cmap
=cmap
)
221 if (show_cb
is True):
222 cb
= plt
.colorbar(pot
)
223 cb
.set_label(cblabel
)
225 print "plotting dimer onto the basemap..."
226 if (cof_only
is False):
227 cof
= ax
.plot(trunc_cofx
, trunc_cofy
, c
='green', marker
='.',
228 lw
=1, label
='cof', alpha
=0.5)
229 x1
= ax
.scatter(set_p1x
, set_p1y
, c
='black', marker
='o', lw
=0, s
=msize
, label
='x1')
230 x2
= ax
.scatter(set_p2x
, set_p2y
, c
='grey', marker
='o', lw
=0, s
=msize
, label
='x2')
233 for i
in range(len(set_p1x
)):
234 if trunc_t
[i
] >= k
*every
:
235 #print "plotting because",t[i],"=",k,"*",every,"(",k*every,")"
236 bond
= ax
.arrow(set_p1x
[i
], set_p1y
[i
],
238 set_pydiff
[i
], color
='black',
241 velo
= ax
.arrow(set_cofx
[i
], set_cofy
[i
],
242 2*set_vx
[i
], 2*set_vy
[i
],
244 head_width
=0.15, shape
='full',
247 elif trunc_t
[i
] < k
*every
:
248 #print "not plotting because",t[i],"!=",k,"*",every,"(",k*every,")"
250 elif (cof_only
is True):
251 cof
= ax
.scatter(trunc_cofx
, trunc_cofy
, c
='red', marker
='o',
252 lw
=0, s
=msize
/4, label
='cof')
259 ax
.arrow(limx_min
+L
/2,limy_min
+L
/2, 2*np
.cos(acangle
*np
.pi
/180),
260 2*np
.sin(acangle
*np
.pi
/180), lw
=2.5, color
='blue',
261 head_width
=0.15, shape
='full')
262 ax
.arrow(limx_min
+L
/2,limy_min
+L
/2, -2*np
.cos(acangle
*np
.pi
/180),
263 -2*np
.sin(acangle
*np
.pi
/180), lw
=2.5, color
='blue',
264 head_width
=0.15, shape
='full')
266 ax
.arrow(limx_min
+L
/2,limy_min
+L
/2, 2*np
.cos(dcangle
*np
.pi
/180),
267 2*np
.sin(dcangle
*np
.pi
/180), lw
=2.5, color
='red',
268 head_width
=0.15, shape
='full')
270 if (show_annotations
is True):
271 for i
in range(len(tcx
)):
272 fig
.text(tcx
[i
],tcy
[i
],tl
[i
],bbox
=dict(boxstyle
="round",
273 fc
=(1.0, 0.7, 0.7), ec
="none"))
276 ax
.set_xlabel(xlabel
, size
=fs_labels
)
277 ax
.set_ylabel(ylabel
, size
=fs_labels
)
278 ax
.set_xticks(xticks
)
279 ax
.set_yticks(yticks
)
280 ax
.set_xlim(limx_min
,limx_max
)
281 ax
.set_ylim(limy_min
,limy_max
)
282 ax
.set_xticklabels(tlabel
, size
=fs_ticks
)
283 ax
.set_yticklabels(tlabel
, size
=fs_ticks
)
285 if (show_legend
is True):
286 legend
= fig
.legend((x1
, x2
, bond
), (r
'$\vec{r}_1$',
287 r
'$\vec{r}_2$', r
'$|\vec{r}_1-\vec{r}_2|$'), shadow
=True,
290 elif (cof_only is True):
291 legend = fig.legend((cof),(r'$\vec{r}_s$'), shadow=True, fancybox=True)
295 #legend.get_frame().set_alpha(0.75)
300 print "saving to file.."
304 if (show_plot
is True):
305 print "showing plot..."