如果运行下面的代码,您会看到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)
答案 0 :(得分:1)
基于this的答案,您需要先关闭默认的自动旋转,然后再应用90度(或-270度)的手动旋转角度
ax.zaxis.set_rotate_label(False)
ax.set_zlabel(r'$(|E|_t)^{A}$', rotation=90, fontsize=16, labelpad=10)