Matplotlib:在3D su上绘制3D曲线

2024-04-19 18:16:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在Matplotlib中在三维曲面的顶部绘制一条三维曲线,但当曲线位于曲面前面时,几乎看不见(曲线是单位圆的图像): enter image description here 表面上方应有一条绿色曲线。
如果从侧面观察,可以看到不在曲面前面的曲线部分(曲面中心峰左侧和右侧的小循环): enter image description here

有没有办法让这个工作起来?我尝试过白色表面,有和没有抗锯齿,但没有效果。在

这是我使用的代码:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')

N = 5

# Make H surface
X = np.linspace(-1.25, 1.25, 1024)
Y = np.linspace(-1.25, 1.25, 1024)
X, Y = np.meshgrid(X, Y)
Z = 1/N * np.abs(1 - (X + Y*1j)**-N) / np.abs(1 - 1/(X + Y*1j))
Z = 20 * np.log10(Z)

# Make the image of the unit circle
omega = np.linspace(0, 2*np.pi, 2048)
circ_X = np.cos(omega)
circ_Y = np.sin(omega)
circ_Z = 1/N * np.sin(N*omega/2) / np.sin(omega/2)
circ_Z = 10 * np.log10(circ_Z**2) + 1

# Plot the H surface and the unit circle
surf = ax.plot_surface(X, Y, Z, cmap=cm.plasma, linewidth=0, antialiased=True)
circ = ax.plot(circ_X, circ_Y, circ_Z, color='green')

ax.set_zlim(-40, 10)
plt.show()

Tags: thefromimportmatplotlibnppltsinax