python - 切换 3D 绘图的 x 轴和 y 轴的位置
问题描述
我正在使用 Matplotlib 制作 3D 图表,并注意到默认设置是“左侧”是 y 轴,右侧是 x 轴,我想知道是否可以切换它们。这是我制作的代码和图像:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim(-3, 5)
ax.set_ylim(-3, 5)
ax.set_zlim(-3, 5)
ax.view_init(elev=20, azim=32)
# u
ax.quiver(0, 0, 0, 2, -1, 0, color='C0', arrow_length_ratio=0.1, label=r'$\vec{u}$')
plt.plot([2, 2], [0, -1], 'k--', linewidth=1)
plt.plot([0, 2], [-1, -1], 'k--', linewidth=1)
# v
ax.quiver(0, 0, 0, -1, 2, -1, color='C1', arrow_length_ratio=0.1, label=r'$\vec{v}$')
ax.plot([0, -1], [2, 2], [0, 0], 'k--', linewidth=1)
ax.plot([-1, -1], [0, 2], [0, 0], 'k--', linewidth=1)
ax.plot([-1, -1], [2, 2], [0, -1], 'k--', linewidth=1)
# w
ax.quiver(0, 0, 0, 0, -1, 2, color='C2', arrow_length_ratio=0.1, label=r'$\vec{w}$')
ax.plot([0, 0], [-1, -1], [0, 2], 'k--', linewidth=1)
ax.plot([0, 0], [-1, 0], [2, 2], 'k--', linewidth=1)
# b
ax.quiver(0, 0, 0, 1, 0, 0, color='C3', arrow_length_ratio=0.2, label=r'$\vec{b}$', linewidth=3)
plt.legend()
ax.set_xlabel(r'$x$', fontsize='large')
ax.set_ylabel(r'$y$', fontsize='large')
ax.set_zlabel(r'$z$', fontsize='large')
ax.quiver(-3, 0, 0, 8, 0, 0, color='k', arrow_length_ratio=0.05) # x-axis
ax.quiver(0, -3, 0, 0, 8, 0, color='k', arrow_length_ratio=0.05) # y-axis
ax.quiver(0, 0, -3, 0, 0, 8, color='k', arrow_length_ratio=0.05) # z-axis
plt.show()
此代码生成以下图像:
如您所见,y 轴位于左侧,x 位于右侧。有没有办法让我切换这些?
谢谢。
解决方案
推荐阅读
- scala - 在包 Intellij IDEA 中找不到套件类
- java - for循环初始化语句Java中的变量范围
- javascript - 如何使用 selenium webdriver 处理角度覆盖并从下拉列表中选择多个值(来自 excel)
- sql - 我在 PostgreSQL 中遇到语法错误问题。我正在尝试添加一个查询,但它给了我一个错误
- react-native - react-native-image-slider-box 未按预期工作
- javascript - React - 组件未更新
- python - 如何将HSV色彩空间的V通道的值设置为恒定值
- ffmpeg - FFMPEG 将不正确的 mp4 转换为 ts
- javascript - 为什么 console.table 仅在深度级别 2 打印(使用 toString)有限的元素
- javascript - 如何延迟获取请求直到异步函数完成加载