3D matplotlib 图中 y 轴和 z 轴的交换位置 [英] Interchange location of y and z axis in 3D matplotlib plot
问题描述
默认情况下,使用 matplotlib
在3D中绘制一组点(或其他点),垂直定位 z
轴,如此处所示(以下代码):>
我需要交换 z
和 y
轴,以便 y
轴垂直显示.
我环顾四周,但发现没有办法告诉 matplotlib
这样做.
添加:我不想在交换数据和标签的过程中使用黑客手段.这是一个简单的3点3D图,但是我必须绘制更复杂的曲面.我正在寻找一种 general 解决方案,而不仅仅是一种适用于散点图的解决方案.一种告诉 matplotlib
垂直放置 y
轴而不是 z
轴的简单方法是 clean 方法做吧.
MWE
将matplotlib.pyplot导入为plt从mpl_toolkits.mplot3d导入Axes3D无花果= plt.figure()ax = Axes3D(图)ax.scatter([0.2, 0.5, 0.8], [2.3, 0.47, 1.], [2.1, 5.3, 0.7])ax.set_xlabel('x')ax.set_ylabel('y')ax.set_zlabel('z')plt.show()
我认为目前尚不可能. ax.view_init()
也需要接受第三个角度.我在github上打开了一个问题, https://github.com/matplotlib/matplotlib/issues/14453#issue-452397120 ,我们希望有人致力于实现此功能.
By default, plotting a set of points (or whatever) in 3D with matplotlib
, locates the z
axis vertically, as seen here (code below):
I need to interchange the z
and y
axis, so that that y
axis is shown vertically.
I've looked around but found no way to tell matplotlib
to do this.
Add: I do not want to have to resort to a hack where I interchange the data and labels. This is a simple 3 points 3D plot, but I have to plot much more complicated surfaces. I'm looking for a general solution, not just something that works with scatter plots. A simple way to tell matplotlib
to put the y
axis vertically instead of the z
axis is the clean way to do it.
MWE
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter([0.2, 0.5, 0.8], [2.3, 0.47, 1.], [2.1, 5.3, 0.7])
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()
I don't think that this is currently possible. ax.view_init()
would need to accept a third angle too.
I opened an issue over at github, https://github.com/matplotlib/matplotlib/issues/14453#issue-452397120, let's hope someone is committed to implement this feature.
这篇关于3D matplotlib 图中 y 轴和 z 轴的交换位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!