【问题标题】:mplot3d: Hiding a line plot `plot()` under a `plot_surface()`mplot3d:在 `plot_surface()` 下隐藏线图`plot()`
【发布时间】:2018-06-12 15:33:18
【问题描述】:

编辑:我在这里描述的问题不再显示在当前版本的 matplotlib(2.1.1,2019 年 9 月 10 日编辑)中:肯定是从那时起修复的错误

我想要一个被Axis.plot_surface() 生成的表面部分覆盖的线图(用Axis.plot() 绘制)。我写了以下脚本:

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

resolution = 100
ax = plt.gca(projection="3d")
x, y = np.meshgrid( np.linspace(-1.0, 1.0, resolution) ,
                    np.linspace(-1.0, 1.0, resolution) )
phi = (1.0 - x)*(1.0 - y) / 4.0
ax.plot([-1.0,1.0], [-1.0,1.0], [0.0,0.0], color="red")
ax.plot_surface(x, y, phi, linewidth=0, antialiased=False)
plt.show()

并确保在拨打plot_surface() 之前先拨打plot()。尽管如此,线图似乎总是具有最高的“zindex”并且被绘制在表面上。这是我得到的:

这是我想要的:

我如何实现这个结果? (不使用 Gimp……)

【问题讨论】:

标签: matplotlib mplot3d


【解决方案1】:

我变了。

ax.plot_surface(x, y, phi, linewidth=0, antialiased=False)

与:

ax.plot_surface(x, y, phi, linewidth=0, antialiased=True)

然后我看到了整条红线 It shows the plot with red line

【讨论】:

  • 我们的目标是看到红线,因为它在地表以下。但是 matplotlib 仍然展示了它的全部内容。话虽如此,我再次运行了原始帖子中的代码……它成功了!肯定是在当前版本的 matplotlib 和我写原始帖子时的版本之间修复的错误。
猜你喜欢
  • 1970-01-01
  • 2011-12-14
  • 1970-01-01
  • 2012-04-15
  • 1970-01-01
  • 2017-10-19
  • 1970-01-01
  • 1970-01-01
  • 2014-04-29
相关资源
最近更新 更多