python - Z轴标签matplotlib垂直方向读错方向——如何向上旋转?

标签 python matplotlib

如果运行下面的代码,您将看到 Z 标签向上:它向下读,但应该向上读。

我输入rotation=0参数中,但无济于事。

如何改变它?

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection, Line3DCollection
from matplotlib import rc
rc('text', usetex=True)

def plot_cube(cube_definition):
    cube_definition_array = [
        np.array(list(item))
        for item in cube_definition
    ]

    points = []
    points += cube_definition_array
    vectors = [
        cube_definition_array[1] - cube_definition_array[0],
        cube_definition_array[2] - cube_definition_array[0],
        cube_definition_array[3] - cube_definition_array[0]
    ]

    points += [cube_definition_array[0] + vectors[0] + vectors[1]]
    points += [cube_definition_array[0] + vectors[0] + vectors[2]]
    points += [cube_definition_array[0] + vectors[1] + vectors[2]]
    points += [cube_definition_array[0] + vectors[0] + vectors[1] + vectors[2]]

    points = np.array(points)

    edges = [
        [points[0], points[3], points[5], points[1]],
        [points[1], points[5], points[7], points[4]],
        [points[4], points[2], points[6], points[7]],
        [points[2], points[6], points[3], points[0]],
        [points[0], points[2], points[4], points[1]],
        [points[3], points[6], points[7], points[5]]
    ]

    fig = plt.figure(figsize=(15, 10), facecolor='w')
    ax = fig.add_subplot(111, projection='3d')

    faces = Poly3DCollection(edges, linewidths=1, edgecolors='k', linestyles= '--')
    faces.set_facecolor((1,1,1,0.1))

    ax.add_collection3d(faces)

    # Plot the points themselves to force the scaling of the axes
    ax.scatter(points[:,0], points[:,1], points[:,2], s=0)

    ax.set_aspect('equal')
    ax.set_xlabel(r'$(|B|_t)^{\beta_0}$', rotation=0, fontsize=16, labelpad=10)
    ax.set_zlabel(r'$(|E|_t)^{A}$', rotation=0, fontsize=16, labelpad=10)
    ax.set_ylabel(r'$(|D|_t)^{\beta_1}$', rotation=0, fontsize=16, labelpad=10)
    ax.view_init(elev=15, azim=30)


cube_definition = [
    (0,0,0), (0,1,0), (1,0,0), (0,0,1)
]
plot_cube(cube_definition)

最佳答案

基于this答案,您需要先关闭默认的自动旋转,然后再应用手动所需的 90 度(或 -270 度)旋转

ax.zaxis.set_rotate_label(False) 
ax.set_zlabel(r'$(|E|_t)^{A}$', rotation=90, fontsize=16, labelpad=10)

enter image description here

关于python - Z轴标签matplotlib垂直方向读错方向——如何向上旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54846960/

相关文章:

python - 读取txt文件,结果为空行

python - 随机图Python networkx读取文件并绘制图表

python - 带上标的 matplotlib 刻度轴符号

python - 将时间轴年份格式化为数字,月份格式化为大写缩写

python - Jupyter notebook 中的 Matplotlib 动画创建额外的空图

比异步更快的 Python 同步代码示例

python - 如何重命名路径名?

python - MySQLdb 错误 : 'Unknown Database Python' using MySQL Workbench

python - 计算相关矩阵子集的最快方法

python - Matplotlib - 更改单个 x 轴刻度标签的颜色