简体   繁体   English

使用Python绘制3D轴上的平行标签

[英]Parallel Labels on 3D axes plot with Python

How can I turn the label of the axes on a 3D plot from this: 我该如何在3D图上旋转轴的标签:

(Labels "perpendicular" to the axes) (标签“垂直于”轴)

在此处输入图片说明

To this: (Labels "parallel" to the axes) 为此:(标签“平行于”轴)

在此处输入图片说明 Perhaps, with the Y label in this case turned of 90 degree . 也许,在这种情况下,将Y label旋转90 degree

I simply use ax.set_xlabel('X axis') , and respective, for each of the three axis, but the labels result perpendicular, and occupy a substantial part of the plot. 我只对三个轴分别使用ax.set_xlabel('X axis')和,但是标签的结果是垂直的,并占据了绘图的很大一部分。

I was reading this discussion , but it is actually not answered, and the get module I don't know where it comes from (I receive error if I try that solution). 我正在阅读此讨论 ,但实际上没有得到答复,而且我不知道get模块的来源(如果尝试该解决方案,则会收到错误)。

I am guessing that you imported axes3d module. 我猜您导入了axes3d模块。 Because it seems from looking at the matplotlib gallery examples, that the default behaviour of axes3d is to have labels "perpendicular", as on your first plot. 因为从查看matplotlib画廊示例来看, axes3d的默认行为是像在您的第一个绘图上那样具有标签“ perpendicular”。 But the module Axes3D have default labels to be "parallel" to the axes, as on your second plot. 但是模块Axes3D默认标签与轴“平行”,如第二张图所示。

As for discussion you linked, it applies to matplab and not to matplotlib. 至于您链接的讨论,它适用于matplab而不适用于matplotlib。

Here is a code that should work for you: 这是适合您的代码:

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

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

points = np.random.rand(3, 40)

ax.scatter(points[0], points[1], points[2])

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()

I have found the following as the best workaround: 我发现以下是最佳解决方法:

ax.zaxis.set_rotate_label(False) # To disable automatic label rotation

ax.set_ylabel('Y')
ax.set_xlabel('X', rotation=-90)
ax.set_zlabel('Z', rotation=90)

From here . 这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM