3D matplotlib 图中 y 轴和 z 轴的交换位置 [英] Interchange location of y and z axis in 3D matplotlib plot

查看:34
本文介绍了3D matplotlib 图中 y 轴和 z 轴的交换位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,使用 matplotlib 在 3D 中绘制一组点(或其他点),垂直定位 z 轴,如下所示(代码如下):

我需要交换 zy 轴,以便 y 轴垂直显示.

我环顾四周,但发现没有办法告诉 matplotlib 这样做.

补充:我不想求助于黑客来交换数据和标签.这是一个简单的 3 点 3D 绘图,但我必须绘制更复杂的曲面.我正在寻找通用解决方案,而不仅仅是适用于散点图的解决方案.一种告诉 matplotlib 垂直放置 y 轴而不是 z 轴的简单方法是 clean 方法做吧.

<小时>

MWE

将 matplotlib.pyplot 导入为 plt从 mpl_toolkits.mplot3d 导入 Axes3Dfig = 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屋!

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