简体   繁体   English

2D线未与3D图上的表面清晰显示

[英]2D line not showing clearly along with surface on 3D plot

I am trying to plot a 1D line along with a 2D surface in matplotlib with Axes3D: 我正在尝试使用Axes3D在matplotlib中绘制1D线和2D表面:

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


x = np.arange(-1., 1.1, 0.1)
y = x.copy()
X, Y = np.meshgrid(x, y)
Z = np.abs(X) + np.abs(Y)

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

ax.plot(np.zeros_like(y), y, 1, color='k')
ax.plot(x, np.zeros_like(x), 1, color='k')

surf = ax.plot_surface(X, Y, Z, color='w')

plt.show(block=False)

but the 2D plot somehow hides the lines: 但是2D图以某种方式隐藏了线条:

在此处输入图片说明

If I comment the surf = plot_surface(...) code line, the 1D lines show correctly: 如果我注释surf = plot_surface(...)代码行,则1D行正确显示: 如果我注释<code> surf = </ code>代码行

How can I have the lines showing correctly along with the surface? 如何使线条与表面正确显示?

Axes3D.plot_surface() apparently accepts a transparency ( alpha ) argument, which actually gets forwarded to a base class, Poly3DCollection. Axes3D.plot_surface()显然接受一个透明( alpha )参数,该参数实际上被转发给基类Poly3DCollection。

And of course the line plot() calls accept a linewidth argument. 当然,line plot()调用接受一个linewidth参数。

So if you render the line plots with thicker lines and you render the surface with some transparency, you should be able to find a combination of settings which let you see both the lines and the surface in a balanced way. 因此,如果用较粗的线渲染线图,并以一定的透明度渲染曲面,则应该能够找到设置的组合,使您可以平衡地看到线条和曲面。

https://matplotlib.org/tutorials/toolkits/mplot3d.html#mpl_toolkits.mplot3d.Axes3D.plot_surface https://matplotlib.org/tutorials/toolkits/mplot3d.html#mpl_toolkits.mplot3d.Axes3D.plot_surface

https://matplotlib.org/api/_as_gen/mpl_toolkits.mplot3d.art3d.Poly3DCollection.html#mpl_toolkits.mplot3d.art3d.Poly3DCollection https://matplotlib.org/api/_as_gen/mpl_toolkits.mplot3d.art3d.Poly3DCollection.html#mpl_toolkits.mplot3d.art3d.Poly3DCollection

You can also achieve this by using the zorder in the plot_surface and plot commands to make the lines sit on top of the surface. 您也可以通过实现这个zorderplot_surfaceplot命令进行线坐于表面的顶部。 Eg 例如

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

x = np.arange(-1., 1.1, 0.1)
y = x.copy()
X, Y = np.meshgrid(x, y)
Z = np.abs(X) + np.abs(Y)

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

surf = ax.plot_surface(X, Y, Z, color='w', zorder=1)

ax.plot(np.zeros_like(y), y, 1, color='k', zorder=10)
ax.plot(x, np.zeros_like(x), 1, color='k', zorder=11)


plt.show(block=False)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM