mplot3d: Hiding a line plot `plot()` under a `plot_surface()`

强颜欢笑 提交于 2020-01-04 05:50:12

问题


Edit: the problem I describe here no longer shows with current versions of matplotlib (2.1.1, edit made on 10 Sep 2019): most certainly a bug that has been fixed since then

I want to have a line plot (drawn with Axis.plot()) that is partially covered by the surface generated by Axis.plot_surface(). I wrote the following script:

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()

and made sure to have the call to plot() before the one to plot_surface(). Nevertheless, it seems that the line plot always has the highest "zindex" and gets plotted over the surface. Here is what I obtain:

Here is what I would like to have instead:

How do I achieve this result? (Without using Gimp…)


回答1:


I changed.

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

with:

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

and then I saw the whole red line It shows the plot with red line



来源:https://stackoverflow.com/questions/50820881/mplot3d-hiding-a-line-plot-plot-under-a-plot-surface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!