来自 Matplotlib 的窗格边缘可见性的 3D 图形 [英] 3D figures from Matplotlib visibility of pane edge

查看:30
本文介绍了来自 Matplotlib 的窗格边缘可见性的 3D 图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法看到左侧窗格边缘.

I am not able to get the left pane edge visible.

%pylab inline
from mpl_toolkits.mplot3d import axes3d
rcdefaults()

x, y = meshgrid(linspace(-10, 10, 100), linspace(-10, 10, 100))
z = x**2+y**2

fig = figure(figsize=[16, 9])
ax3D = fig.add_subplot(111, projection='3d')
ax3D.plot_surface(x, y, z, rstride=8, cstride=8, alpha=0.3, cmap='hot')  
ax3D.contour(x, y, z, zdir='x', offset=ax3D.get_xlim()[0])
ax3D.contour(x, y, z, zdir='y', offset=ax3D.get_ylim()[1])
ax3D.contour(x, y, z, zdir='z', offset=ax3D.get_zlim()[0])
ax3D.xaxis.pane.set_edgecolor('#000000')
ax3D.yaxis.pane.set_edgecolor('#000000')
ax3D.zaxis.pane.set_edgecolor('#000000')
ax3D.xaxis.pane.set_alpha(1)
ax3D.yaxis.pane.set_alpha(1)
ax3D.zaxis.pane.set_alpha(1)
ax3D.xaxis.pane.fill = False
ax3D.yaxis.pane.fill = False
ax3D.zaxis.pane.fill = False
fig.savefig('test')

一个不令人满意的解决方法是通过反转 x 和 y 轴将标记的 ax 放在此特定窗格边缘:

An unsatisfactory workaround is to put a labeled ax on this particular pane edge by inverting the x and y axis:

ax3D.invert_yaxis()
ax3D.invert_xaxis()

使用 Poly3DCollection 线补丁的更好解决方法几乎可以做到.除了检索到的限制似乎不太正确.

A better workaround using a Poly3DCollection line patch almost does it. Except that the retrieved limits don't seem quite right.

from mpl_toolkits.mplot3d import art3d

i = array([ax3D.get_xlim3d()[0], ax3D.get_ylim3d()[0], ax3D.get_zlim3d()[0]])
f = array([ax3D.get_xlim3d()[0], ax3D.get_ylim3d()[0], ax3D.get_zlim3d()[1]])
p = art3d.Poly3DCollection(array([[i, f]]))
p.set_color('black')
ax3D.add_collection3d(p)

推荐答案

因此,这是我对此问题的解释或更好的解决方法:

So here is my somewhat hacky answer or better said workaround for this problem:

%pylab inline
%matplotlib notebook
%matplotlib notebook
from mpl_toolkits.mplot3d import axes3d, art3d
rcdefaults()

x, y = meshgrid(linspace(-10, 10, 100), linspace(-10, 10, 100))
z = x**2+y**2

fig = figure()
ax3D = fig.add_subplot(111, projection='3d')
ax3D.plot_surface(x, y, z, rstride=8, cstride=8, alpha=0.3, cmap='hot')

def lims(mplotlims):
    scale = 1.021
    offset = (mplotlims[1] - mplotlims[0])*scale
    return mplotlims[1] - offset, mplotlims[0] + offset
xlims, ylims, zlims = lims(ax3D.get_xlim()), lims(ax3D.get_ylim()), lims(ax3D.get_zlim())
ax3D.contour(x, y, z, zdir='x', offset=xlims[0])
ax3D.contour(x, y, z, zdir='y', offset=ylims[1])
ax3D.contour(x, y, z, zdir='z', offset=zlims[0])
i = array([xlims[0], ylims[0], zlims[0]])
f = array([xlims[0], ylims[0], zlims[1]])
p = art3d.Poly3DCollection(array([[i, f]]))
p.set_color('black')
ax3D.add_collection3d(p)

ax3D.xaxis.pane.set_edgecolor('#000000')
ax3D.yaxis.pane.set_edgecolor('#000000')
ax3D.zaxis.pane.set_edgecolor('#000000')
ax3D.xaxis.pane.set_alpha(1)
ax3D.yaxis.pane.set_alpha(1)
ax3D.zaxis.pane.set_alpha(1)
ax3D.xaxis.pane.fill = False
ax3D.yaxis.pane.fill = False
ax3D.zaxis.pane.fill = False
fig.tight_layout()
show()

这篇关于来自 Matplotlib 的窗格边缘可见性的 3D 图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆