I'm trying to replicate the following plot using python and matplotlib. However, the best I have been able to produce is the following
The main issue here is the not in-plane arrows heads, even if I am not satisfied with the quality of the plot in general. I've searched for a solution to use a 2D quiver in a 3D plot but I haven't found any useful information about how to do that. Do you know any other way to achieve in-plane arrowheads? In general, any suggestion on how to improve the quality of this plot would be welcomed.
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
params = {
'font.family' : 'serif',
'mathtext.fontset': 'stix',
'axes.labelsize': 13,
'legend.fontsize': 8,
'xtick.labelsize': 13,
'ytick.labelsize': 13,
'text.usetex': True,
'figure.figsize': [10, 5]
}
plt.rcParams.update(params)
plt.close('all')
x_ax = np.linspace(-10, 10, 24)
y_ax = np.linspace(-10, 10, 24)
x, y = np.meshgrid(x_ax, y_ax, indexing='ij')
r = np.sqrt(x**2 + y**2)
j_x = -y/r*(- np.exp(-np.abs(r)) + np.exp(-np.abs(r)/2) )*2
j_y = +x/r*(- np.exp(-np.abs(r)) + np.exp(-np.abs(r)/2) )*2
#c = np.arctan2(x, -y)
c = np.sqrt(j_x**2 + j_y**2)
c = (c.ravel() - c.min()) / c.ptp()
c = np.concatenate((c, np.repeat(c, 2)))
c = cm.jet(c)
#c = plt.cm.hsv(c)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.quiver(x, y, 0, j_x, j_y, 0, colors=c, length=1.2, pivot='middle')
t = np.linspace(-10, 10, 200)
psi = 1 - np.exp(-np.abs(t))
b = np.exp(-t**2)
j_abs = np.abs(t)*np.exp(-t**2)*2
#j_abs = (- np.exp(-np.abs(t)) + np.exp(-np.abs(t)/2) )*2
ax.plot(t, psi, zs=0, zdir='y', label=r"$|\psi|$")
ax.plot(t, b, zs=0, zdir='y', label=r"$|\vec B|$")
ax.plot(t, j_abs, zs=0, zdir='y', label=r"$|\vec j|$")
ax.legend()
ax.set_proj_type('ortho')
ax.set_axis_off()
ax.set_zlim([-0.2, 1.4])
ax.view_init(elev=45, azim=90)
ax.dist=5
fig.savefig("vortex.pdf", bbox_inches="tight")
from How to rotate arrowheads in 3D quiver in matplotlib?
No comments:
Post a Comment