【发布时间】:2018-07-04 16:37:24
【问题描述】:
我正在尝试移动 3D matplotlib 轴对象中的脊椎。
这似乎是一个非常简单的问题,但我没有找到任何直接解决这个问题的问题/答案。我在这个问题的底部包含了我对此主题的研究列表。
我可以在 matplotlib 2D 图中设置刺的位置。以下代码:
import matplotlib.pyplot as plt, numpy as np
fig, axes = plt.subplots(1, 2)
r, theta = 1, np.linspace(0, 2*np.pi, 100)
x, y = r*np.cos(theta), r*np.sin(theta)
for ax in axes: # plot the same data on both axes
ax.plot(x, y)
ax.set_aspect("equal")
for spine in ax.spines.values(): # adjust spines on last active axis
spine.set_position(("data", 0))
但是,当我尝试使用 3D 轴做同样的事情时......
z = np.zeros(x.shape) # exciting stuff
fig = plt.figure()
for i in range(2): # create two 3D subplots
ax = plt.subplot(1,2,i+1, projection="3d", aspect="equal")
plt.plot(x, y, z)
for spine in ax.spines.values(): # adjust spines on last active axis
spine.set_position(("data", 0))
上面的代码给了我:
即没有效果,即使代码仍然运行。此外,对于 3D 轴,ax.spines 看起来像:
OrderedDict([('left', <matplotlib.spines.Spine at 0x120857b8>),
('right', <matplotlib.spines.Spine at 0xfd648d0>),
('bottom', <matplotlib.spines.Spine at 0xe89e4e0>),
('top', <matplotlib.spines.Spine at 0xe89eef0>)])
我不确定在 3D 轴的上下文中“左”、“右”、“下”、“上”指的是什么。我试过改变其他属性,比如刺的颜色;那里也没有运气。我怎样才能掌握轴上的实际 x、y、z 刺?
研究:
- 在撰写本文时,在 stackoverflow 中搜索“matplotlib spines 3d”会得到 5 个结果(包括这个问题)。
-
mplot3d文档根本没有提到脊椎。 -
This question 展示了如何使用
ax.w_xaxis.set_pane_color()设置窗格颜色,但没有类似的ax.w_zaxis.set_spine...方法。 -
This question 展示了如何使用
ax.w_zaxis.line.set_color()设置书脊颜色。我想过做一个可怕的解决方法来手动设置ax.w_zaxis.line.set_data,但它只有 x 和 y 数据;没有z!甚至 x 和 y 轴也没有 z 数据。
【问题讨论】:
-
这肯定不是第一次被问到。请务必查看有关此问题的先前问题。我的猜测是实际上不可能以预期的方式移动轴,但我不能肯定地说。
-
@ImportanceOfBeingErnest 是的,我很感激。这是我在问这个问题之前已经搜索了很多次的东西。老实说,很难找到任何甚至提到 3d 脊椎的东西(包括 matplotlib 文档)。针对您的评论,我添加了其他问题的简短摘要,以表明我无法找到现有答案。
标签: python matplotlib plot 3d