some minor tweaks to some mpl files and color filter updates
[quplot.git] / dimer.py
blobbe8bf0c039825262649ff3cca95908bdf1fe4886
1 #!/usr/bin/python
2 # -*- coding: iso-8859-1 -*-
4 import matplotlib as mpl
5 mpl.rc('text', usetex = True)
6 import pylab
7 import numpy as np
8 import matplotlib.cm as cm
9 import matplotlib.mlab as mlab
10 import matplotlib.pyplot as plt
11 import matplotlib.patches as patch
12 import matplotlib.colors as col
14 FOUT = "../latex/images/dimer_intro.png"
16 L = 2*np.pi
17 w = 0.1
18 tau = L/w
19 angle1 = 30
20 angle2 = 60
21 transport_angle = 100
22 phi = 0
23 alpha = 135
24 dimer_length = 0.4
25 cofx = cofy = L/2
26 pad = 0.01 # small padding so the ticks get drawn correctly...
27 msize = 20
28 hw = 0.15 # arrow head width
29 res = (800/80,600/80) # default dpi is 80
30 cmap = cm.gray_r # colormap
31 shader = False # applies ultra cool shadows to the map!
32 show_plot = False
33 xticks = [-2*L,-L,0,L,2*L]
34 yticks = [-2*L,-L,0,L,2*L]
35 tlabel = ["-2L","-L","0","L","2L"]
36 xlabel = r'$x$'
37 ylabel = r'$y$'
38 cblabel = r'$\cos{x}\cos{y}+\cos{x}+\cos{y}$'
39 fs_ticks = 18
40 fs_labels = 28
42 ################################################################################
44 PI = np.pi
45 rad1 = angle1*PI/180
46 rad2 = angle2*PI/180
47 rad_transport = transport_angle*PI/180
48 rad_phi = phi*PI/180
49 rad_alpha = alpha*PI/180
51 limx_min = -L/2
52 limx_max = 1.5*L
53 # quadratic
54 limy_min = limx_min
55 limy_max = limx_max
57 print "generating basemap..."
58 delta = 0.01
59 x = np.arange(limx_min,limx_max, delta)
60 y = np.arange(limy_min,limy_max, delta)
61 X,Y = np.meshgrid(x, y)
62 Z = np.cos(X)*np.cos(Y)+np.cos(X)+np.cos(Y)
63 print "done."
65 fig = plt.figure(figsize=res)
67 ax = fig.add_subplot(111)
69 if (shader is True):
70 print "applying lightsource..."
71 ls = col.LightSource(azdeg=0,altdeg=90)
72 rgb = ls.shade(Z,cmap)
73 print "done."
74 print "plotting basemap..."
75 pot = plt.imshow(rgb, extent=[limx_min,limx_max,limy_min,limy_max])
76 print "done."
77 else:
78 print "plotting basemap..."
79 pot = plt.pcolormesh(X,Y,Z, cmap=cmap)
80 print "done."
82 cb = plt.colorbar(pot)
83 cb.set_label(cblabel, size=fs_labels)
85 print "plotting dimer onto the basemap..."
87 def make_circle(start,stop,r):
88 t = np.arange(start,stop,0.01)
89 #t = t.reshape((len(t), 1))
90 ret_x = cofx + r * np.cos(t)
91 ret_y = cofy + r * np.sin(t)
92 return ret_x, ret_y
95 varphi_plot_x, varphi_plot_y = make_circle(rad1, rad2, 2.0)
96 psi_plot_x, psi_plot_y = make_circle(rad_phi, rad_transport, 0.8)
98 ax.scatter(cofx, cofy, c='yellow', marker='o', lw=0, s=msize*4,
99 label='cof')
100 ax.arrow(cofx, cofy, np.cos(rad1)*dimer_length*L,
101 np.sin(rad1)*dimer_length*L, color='r', lw=0.1, alpha=0.5)
102 ax.arrow(cofx, cofy, np.cos(rad2)*dimer_length*L,
103 np.sin(rad2)*dimer_length*L, color='r', lw=0.1, alpha=0.5)
104 ax.arrow(cofx, cofy, -np.cos(rad1)*dimer_length*L,
105 -np.sin(rad1)*dimer_length*L, color='r', lw=0.1, alpha=0.5)
106 ax.arrow(cofx, cofy, -np.cos(rad2)*dimer_length*L,
107 -np.sin(rad2)*dimer_length*L, color='r', lw=0.1, alpha=0.5)
108 ax.scatter(cofx+np.cos(rad1)*dimer_length*L,
109 cofy+np.sin(rad1)*dimer_length*L, c='blue', marker='o',
110 lw=0, s=msize, label='x1')
111 ax.scatter(cofx-np.cos(rad1)*dimer_length*L,
112 cofy-np.sin(rad1)*dimer_length*L, c='purple', marker='o',
113 lw=0, s=msize, label='x1')
114 ax.scatter(cofx+np.cos(rad2)*dimer_length*L,
115 cofy+np.sin(rad2)*dimer_length*L, c='blue',
116 marker='o', lw=0, s=msize, label='x2')
117 ax.scatter(cofx-np.cos(rad2)*dimer_length*L,
118 cofy-np.sin(rad2)*dimer_length*L, c='purple',
119 marker='o', lw=0, s=msize, label='x2')
120 ax.plot(varphi_plot_x, varphi_plot_y, color='black')
121 ax.arrow(cofx, cofy, np.cos(rad_phi)*0.4*L, np.sin(rad_phi)*0.4*L,
122 head_width=hw, shape='full', color='red')
123 ax.arrow(cofx, cofy, np.cos(rad_transport)*0.4*L,
124 np.sin(rad_transport)*0.4*L, head_width=hw,
125 shape='full')
126 ax.plot(psi_plot_x, psi_plot_y, color='black')
127 ax.arrow(cofx, cofy, np.cos(rad_alpha)*0.4*L, np.sin(rad_alpha)*0.4*L,
128 head_width=hw, shape='full', color='blue')
129 ax.arrow(cofx, cofy, -np.cos(rad_alpha)*0.4*L, -np.sin(rad_alpha)*0.4*L,
130 head_width=hw, shape='full', color='blue')
132 plt.text(cofx+np.cos(rad_phi+0.025)*0.4*L,
133 cofy+np.sin(rad_phi+0.025)*0.4*L,
134 r'$F\vec{e}_{\phi}$',{'color' : 'k', 'fontsize' :
135 fs_labels})
136 plt.text(cofx+np.cos(rad_transport-0.05)*0.4*L,
137 cofy+np.sin(rad_transport-0.05)*0.4*L, r'$\vec{v}$',
138 {'color': 'k', 'fontsize' : fs_labels})
139 plt.text(0.5*L,0.65*L, r'$\psi$', {'color' : 'k', 'fontsize' : fs_labels})
140 plt.text(0.65*L,0.65*L, r'$\varphi$', {'color' : 'k', 'fontsize' :
141 fs_labels})
142 plt.text(cofx+np.cos(rad_alpha-0.025)*0.4*L, cofy+np.sin(rad_alpha-0.025)*0.4*L,
143 r'$A\vec{e}_{\alpha}$', {'color' : 'k', 'fontsize' :
144 fs_labels})
146 ax.set_xlabel(xlabel, size=fs_labels)
147 ax.set_ylabel(ylabel, size=fs_labels)
148 ax.set_xticks(xticks)
149 ax.set_yticks(yticks)
150 ax.set_xlim(limx_min,limx_max)
151 ax.set_ylim(limy_min,limy_max)
152 ax.set_xticklabels(tlabel, size=fs_ticks)
153 ax.set_yticklabels(tlabel, size=fs_ticks)
156 print "saving to file.."
157 plt.savefig(FOUT)
158 print "done."
160 if (show_plot is True):
161 print "showing plot..."
162 plt.show()
163 print "done."