.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/optics/polarization/plot_malus_law.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_optics_polarization_plot_malus_law.py: Malus's law: polarized light through an analyser ================================================ In 1808, looking through a calcite crystal at sunlight reflected from the windows of the Luxembourg Palace, Étienne-Louis Malus saw that one of the two images faded as he turned the crystal: reflection had polarized the light. In 1809 he gave the law for the fraction that a second polarizer (the analyser) passes when its axis is at :math:`\theta` to the light's plane of polarization, .. math:: I = I_0\cos^2\theta. Two crossed polarizers pass nothing, yet putting a third one between them at 45 degrees lets light through again: unpolarized light keeps :math:`1/2` at the first polarizer, :math:`\cos^2 45^\circ = 1/2` of that at the second and :math:`1/2` again at the third, :math:`1/8` in all. With :math:`N` polarizers stepped evenly through 90 degrees the transmitted fraction :math:`\cos^{2N}(\pi/2N)` tends to 1, so polarized light can be turned through a right angle with almost no loss. .. GENERATED FROM PYTHON SOURCE LINES 24-32 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from physicskit.optics import jones_vector, linear_polarizer, mueller_matrix, stokes_vector fig, axes = plt.subplots(1, 3, figsize=(15, 4.2)) .. image-sg:: /api/gallery/optics/polarization/images/sphx_glr_plot_malus_law_001.png :alt: plot malus law :srcset: /api/gallery/optics/polarization/images/sphx_glr_plot_malus_law_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 33-38 The analyser ------------ Horizontally polarized light of unit intensity meets a polarizer whose axis is at theta. The Jones matrix gives the transmitted field, and its squared length is the intensity. .. GENERATED FROM PYTHON SOURCE LINES 38-48 .. code-block:: Python theta = np.radians(np.linspace(0, 360, 361)) E_in = jones_vector(0.0) I = np.array([np.vdot(E, E).real for E in (linear_polarizer(t) @ E_in for t in theta)]) axes[0].plot(np.degrees(theta), I, color="steelblue", lw=2, label="Jones calculus") axes[0].plot(np.degrees(theta[::15]), np.cos(theta[::15]) ** 2, "ko", ms=4, label=r"$\cos^2\theta$") axes[0].set_xlabel(r"analyser angle $\theta$ (deg)") axes[0].set_ylabel(r"$I/I_0$") axes[0].set_title("Malus's law") axes[0].legend(loc="upper right", fontsize=8) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 49-54 Three polarizers ---------------- Unpolarized light has no Jones vector, so this uses the Stokes vector (1, 0, 0, 0) and the Mueller matrix of each polarizer. The first and last are crossed; the middle one turns through phi. .. GENERATED FROM PYTHON SOURCE LINES 54-65 .. code-block:: Python unpolarized = stokes_vector(1.0, 0.0) first, last = mueller_matrix(linear_polarizer(0.0)), mueller_matrix(linear_polarizer(np.pi / 2)) phi = np.radians(np.linspace(0, 180, 181)) I3 = np.array([(last @ mueller_matrix(linear_polarizer(p)) @ first @ unpolarized)[0] for p in phi]) axes[1].plot(np.degrees(phi), I3, color="crimson", lw=2) axes[1].axhline(1 / 8, color="k", ls=":", lw=1) axes[1].annotate("1/8 at 45 deg", (45, 1 / 8), (70, 0.10), arrowprops={"arrowstyle": "->"}) axes[1].set_xlabel(r"middle polarizer angle $\varphi$ (deg)") axes[1].set_ylabel(r"$I/I_0$ (unpolarized input)") axes[1].set_title(r"Crossed polarizers with one between: $\sin^2 2\varphi/8$") .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, 'Crossed polarizers with one between: $\\sin^2 2\\varphi/8$') .. GENERATED FROM PYTHON SOURCE LINES 66-68 Rotating the plane of polarization with N polarizers ---------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 68-85 .. code-block:: Python N = np.arange(1, 41) I_N = [] for n in N: E = E_in for k in range(1, n + 1): E = linear_polarizer(k * np.pi / (2 * n)) @ E I_N.append(np.vdot(E, E).real) axes[2].plot(N, I_N, "o", color="seagreen", ms=4, label="Jones calculus") axes[2].plot(N, np.cos(np.pi / (2 * N)) ** (2 * N), "k-", lw=1, label=r"$\cos^{2N}(\pi/2N)$") axes[2].set_xlabel("number of polarizers N spanning 90 deg") axes[2].set_ylabel(r"$I/I_0$") axes[2].set_ylim(0, 1) axes[2].set_title("Many small steps lose little light") axes[2].legend(fontsize=8) plt.tight_layout() plt.show() .. image-sg:: /api/gallery/optics/polarization/images/sphx_glr_plot_malus_law_002.png :alt: plot malus law :srcset: /api/gallery/optics/polarization/images/sphx_glr_plot_malus_law_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 86-88 Check ----- .. GENERATED FROM PYTHON SOURCE LINES 88-92 .. code-block:: Python assert np.allclose(I, np.cos(theta) ** 2, atol=1e-12) assert abs(I3[45] - 1 / 8) < 1e-12 and abs(I3[0]) < 1e-12 assert np.allclose(I3, np.sin(2 * phi) ** 2 / 8, atol=1e-12) assert np.allclose(I_N, np.cos(np.pi / (2 * N)) ** (2 * N), atol=1e-12) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.043 seconds) .. _sphx_glr_download_api_gallery_optics_polarization_plot_malus_law.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_malus_law.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_malus_law.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_malus_law.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_