.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "matplotlib/plot_parametrix_color.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_matplotlib_plot_parametrix_color.py: colored parametric plot =========================================== .. GENERATED FROM PYTHON SOURCE LINES 8-70 .. image-sg:: /matplotlib/images/sphx_glr_plot_parametrix_color_001.png :alt: plot parametrix color :srcset: /matplotlib/images/sphx_glr_plot_parametrix_color_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import FancyArrowPatch, ArrowStyle from matplotlib.cm import ScalarMappable from matplotlib.colors import Normalize from mpl_toolkits.axes_grid1 import make_axes_locatable def plot(fac, z, cmap, norm): fig, ax, cax = fac arrs = [] for i, (x, y) in enumerate(zip(z.real, z.imag)): c = cmap(norm(i)) ax.scatter(x, y, color = c) if i !=0: style = ArrowStyle('-|>', head_length=0.3) arr = FancyArrowPatch((x0, y0), (x, y), arrowstyle=style, mutation_scale=15, color=c, lw=1) arrs.append(arr) x0 = np.copy(x) y0 = np.copy(y) sm = ScalarMappable(norm=norm, cmap=cmap) sm.set_array([]) cbar = fig.colorbar(sm, cax=cax) for arr in arrs: ax.add_patch(arr) return cbar fig, ax = plt.subplots(1,1) divider = make_axes_locatable(ax) cax1 = divider.append_axes("right", size="3%", pad=0.05) cax2 = divider.append_axes("right", size="3%", pad=0.05) sample = 30 theta = np.linspace(0, 4*np.pi, sample) r = np.linspace(0, 5, sample) z1 = r*np.exp(1.j*theta) z2 = r*np.exp(-1.j*theta) norm = Normalize(vmin=theta[0], vmax=theta[-1]) cbar1 = plot([fig,ax, cax1], z1, plt.cm.GnBu, norm) cbar2 = plot([fig,ax, cax2], z2, plt.cm.Oranges, norm) cbar1.set_ticks([]) cbar2.set_ticks([0, np.pi, 2*np.pi, 3*np.pi, 4*np.pi]) cbar2.set_ticklabels(["$0$", "$\pi$", "$2\pi$", "$3\pi$", "$4\pi$"]) cbar2.set_label(r"$\theta$", fontsize=15) cbar2.ax.yaxis.label.set_rotation(0) plt.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.353 seconds) .. _sphx_glr_download_matplotlib_plot_parametrix_color.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_parametrix_color.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_parametrix_color.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_parametrix_color.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_