matplotlib - 在 mplot3d 中绘制右手坐标系

标签 matplotlib coordinate-systems mplot3d

我想从 3D 坐标变换的 Python 创建图。例如,我想创建以下图像(由 TikZ 静态生成):
enter image description here
经过一番搜索,我找到了以下程序:

import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.patches import FancyArrowPatch
from mpl_toolkits.mplot3d import proj3d


class Arrow3D(FancyArrowPatch):
    def __init__(self, xs, ys, zs, *args, **kwargs):
        FancyArrowPatch.__init__(self, (0, 0), (0, 0), *args, **kwargs)
        self._verts3d = xs, ys, zs

    def draw(self, renderer):
        xs3d, ys3d, zs3d = self._verts3d
        xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
        self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
        FancyArrowPatch.draw(self, renderer)


fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
arrow_prop_dict = dict(mutation_scale=20, arrowstyle='->', shrinkA=0, shrinkB=0)

a = Arrow3D([0, 1], [0, 0], [0, 0], **arrow_prop_dict, color='r')
ax.add_artist(a)
a = Arrow3D([0, 0], [0, 1], [0, 0], **arrow_prop_dict, color='b')
ax.add_artist(a)
a = Arrow3D([0, 0], [0, 0], [0, 1], **arrow_prop_dict, color='g')
ax.add_artist(a)

ax.text(0.0, 0.0, -0.1, r'$o$')
ax.text(1.1, 0, 0, r'$x$')
ax.text(0, 1.1, 0, r'$y$')
ax.text(0, 0, 1.1, r'$z$')

ax.view_init(azim=-90, elev=90)
ax.set_axis_off()
plt.show()
结果看起来不像人们通常在书中看到的那样:
enter image description here
此外,当我包括轴时,原点不在三个平面的交点处,这是我期望的位置。

最佳答案

您可以通过更改以下行来更改 3D 轴的 View :

ax.view_init(azim=-90, elev=90)
ax.view_init(azim=20, elev=10)
重现您的 TikZ 图,或根据您的喜好将视角更改为任何其他值。

关于matplotlib - 在 mplot3d 中绘制右手坐标系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47617952/

相关文章:

python - 更改 3D 图(Matplotlib)的垂直(z)轴的位置?

python - 在 3D 中绘制正态分布

python - 仅绘制热图的上/下三角形

python - 范围在 matplotlib 中的真正作用是什么?

javascript - 如何同步 Three.js 和 HTML/SVG 坐标系(特别是 w.r.t. y 轴)?

python - 检索已展平为二维的三角形上某个点的实际 3D 坐标

python - 将颜色图应用于 Matplotlib 3D 表面中的自定义轴

python - 关闭极坐标 matplotlib 图的轴边界

python - 填充动画中的图形之间

shapefile - Qgis:如何导出坐标为度数的多边形形状文件