Matplotlib - Wrong overlapping when plotting two 3D surfaces on the same axes

后端 未结 3 504
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 21:04

I am trying to plot two 3D surfaces on the same axes in matplotlib with the plot_surface command.

fig = plt.figure()
fig.figsize = fig_size
ax = fig.gca(proj         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 21:25

    One can do a manual fix for this. It is obviously not the most clean solution, but it gives you what you want. Say you want to plot Z1 and Z2 for a common X and Y.

    1. Create an array Z1_gte, being a copy of Z1 where Z1>=Z2 and np.nan otherwise.
    2. Create an array Z1_lte, being a copy of Z1 where Z1<=Z2 and np.nan otherwise.
    3. Plot three surfaces in the following order: Z1_lte, Z2, Z1_gte. When viewing from high to low along the z-axis, your surfaces will look correct. Reverse te order if you want the surfaces to look correct when viewing from low to high along the z-axis.

    Or directly:

    ax.plot_surface(X,Y,np.where(Z1=Z2,Z1,np.nan))
    

    Obvious drawback of this method is that it only works for one specific viewing-direction along the z-axis.

提交回复
热议问题