.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "matplotlib/plot_complex_doublewell.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here <sphx_glr_download_matplotlib_plot_complex_doublewell.py>` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_matplotlib_plot_complex_doublewell.py: Complex contour of a double well potential =========================================== .. GENERATED FROM PYTHON SOURCE LINES 9-93 .. image:: /matplotlib/images/sphx_glr_plot_complex_doublewell_001.png :alt: plot complex doublewell :class: sphx-glr-single-img .. code-block:: default import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D np.seterr(invalid='ignore') def V(q): return (q**2-1)**2 def H(q,p): return p**2/2 + V(q) def P(E,q): return np.sqrt(2*(E-V(q)))+0.j fig = plt.figure(figsize=(10,5)) #fig = plt.figure(figsize=plt.figaspect(0.5)) #fig = plt.figure(figsize=plt.figaspect(0.5)) ax = fig.add_subplot(111,projection='3d') fig.patch.set_visible(False) ax.axis('off') x = np.linspace(-2.0, 2.0, 300) y = np.linspace(-2.0, 2.0, 300) x,y = np.meshgrid(x,y) level = [0.1,0.5, 1.0, 2.0, 3.0, 4.0] ax.contour(x,y,H(x,y),level,zdir='z',offset=0,colors='k') sample=5000 E=0.5 + 0.j q = np.linspace(-0.8, 0.8,sample) + 0.j p = P(E,q) ax.plot(q.real,p.real, p.imag, c="r",lw=3) E=0.5 q = np.linspace(-1.4, 1.4,sample) p = P(E,q) ax.plot(q.real,p.real,0, c="r",lw=3) ax.plot(q.real,-p.real,0, c="r",lw=3) sample=500 q = np.linspace(-1.4, 1.4,sample) + 0.j pp1 = np.array([],dtype=np.complex128) qq1 = np.array([],dtype=np.complex128) pp2 = np.array([],dtype=np.complex128) qq2 = np.array([],dtype=np.complex128) levels = np.linspace(1e-20,0.5,500) for im in levels: p = P(E+1.j*im,q) pp1 = np.append(pp1, p) qq1 = np.append(qq1, q) p = -P(E-1.j*im,q) pp2 = np.append(pp2, p) qq2 = np.append(qq2, q) p = pp1.reshape(sample, sample) q = qq1.reshape(sample, sample) ax.plot_wireframe(q.real,p.real, p.imag,rstride=2,cstride=2,alpha=0.1,colors='c') p = pp2.reshape(sample, sample) q = qq2.reshape(sample, sample) ax.plot_wireframe(q.real,p.real, p.imag,rstride=2,cstride=2,alpha=0.1,colors='c') ax.set_xlabel(r"$Re(q)$",fontsize=20) ax.set_ylabel(r"$Re(p)$",fontsize=20) ax.set_zlabel(r"$Im(p)$",fontsize=20) ax.set_xticks([-1,0,1]) ax.set_yticks([-1,0,1]) ax.set_zticks([0,0.5,1]) ax.set_xlim(-2.0,2.0) ax.set_ylim(-2.0,2.0) ax.set_zlim(0,1.0) #fig.savefig("complex_doubel_well.png",transparent=True) fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.524 seconds) .. _sphx_glr_download_matplotlib_plot_complex_doublewell.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_complex_doublewell.py <plot_complex_doublewell.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_complex_doublewell.ipynb <plot_complex_doublewell.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_