Chirality indicated in draw_ellipse_jones
Issue #3
resolved
It could be useful, in the case of circularly or elliptically polarized light, to indicate the chirality visually in the ‘draw ellipse’ routine.
The code below shows one primitive implementation, under the if draw_arrow:
block of each function.
def draw_ellipse_jones(j0, limit='', filename='', draw_arrow=False):
"""Draws polarization ellipse of Jones vector.
Parameters:
j0 (Jones_vector): Jones vector
limit (float): limit for drawing. If empty itis obtained from ampltiudes.
filename (str): name of filename to save the figure.
Returns:
fig (handle): handle to figure.
ax (handle): handle to axis.
"""
E_field = j0.get()
E0x = asarray(E_field[0]).squeeze()
E0y = asarray(E_field[1]).squeeze()
angles = linspace(0, 360 * degrees, 90)
Ex = real(E0x * exp(1j * angles))
Ey = real(E0y * exp(1j * angles))
max_size = (sqrt(Ex**2 + Ey**2)).max() * 1.1
if limit in [0, '', [], None]:
limit = max_size * 1.25
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(Ex, Ey, 'k', lw=2, label='polarized')
if draw_arrow:
ax.arrow(Ex[0],Ey[0],Ex[1]-Ex[0],Ey[1]-Ey[0], width = 0, head_width = 0.1, fc='k', ec='k', length_includes_head=True)
plt.axis('equal')
plt.axis('square')
plt.grid(True)
ax.set_xlim(-limit, limit)
ax.set_ylim(-limit, limit)
ax.set_xlabel('$E_x$', fontsize=22)
ax.set_ylabel('$E_y$', fontsize=22)
plt.tight_layout()
if filename not in (None, [], ''):
plt.savefig(filename)
return fig, ax
def draw_ellipses_jones(Jones_vectors, filename='', draw_arrow=False):
"""Draws several one or several Jones vectors.
Parameters:
Jones_vectors (list or Jones_vector): Jones_vector or list of Jones vectors
filename (str): name of filename to save the figure.
"""
colors = [
'k', 'r', 'g', 'b', 'k--', 'r--', 'g--', 'b--', 'k-.', 'r-.', 'g-.',
'b-.'
]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_aspect('equal')
plt.axis('square')
if Jones_vectors is not None:
Jones_vectors = asarray(Jones_vectors)
for i, ji in enumerate(Jones_vectors):
E0x = asarray(ji.M[0]).squeeze()
E0y = asarray(ji.M[1]).squeeze()
angles = linspace(0, 360 * degrees, 90)
Ex = real(E0x * exp(1j * angles))
Ey = real(E0y * exp(1j * angles))
i_color = remainder(i, len(colors))
ax.plot(Ex, Ey, colors[i_color], lw=2, label=ji.name)
if draw_arrow:
ax.arrow(Ex[0],Ey[0],Ex[1]-Ex[0],Ey[1]-Ey[0], width = 0, head_width = 0.1, fc=colors[i_color], ec=colors[i_color], length_includes_head=True)
# ax.set_xticklabels([])
# ax.set_yticklabels([])
plt.grid(True)
ax.set_xlabel('$E_x$', fontsize=22)
ax.set_ylabel('$E_y$', fontsize=22)
max_size = (sqrt(Ex**2 + Ey**2)).max() * 1.1
ax.set_xlim(-max_size, max_size)
ax.set_ylim(-max_size, max_size)
plt.legend()
plt.tight_layout()
if filename not in (None, [], ''):
plt.savefig(filename)
return ax, fig
Thanks for your consideration.
PS
Comments (3)
-
repo owner -
repo owner - changed status to closed
-
repo owner - changed status to resolved
- Log in to comment
Thank you very much for your proposal.
It has been included in the 0.2.1 version.
LMSB