将所有标签值远离轴移动 [英] Shifting all label values far from axis

查看:39
本文介绍了将所有标签值远离轴移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个表面图,但是问题是我的刻度标签和轴标签彼此重叠.有什么办法可以使标签在所有轴上都远离刻度标签?我实际上需要保持刻度标签字体更大,因此缩小字体对于我来说并不理想.

I have created a surface plot but problem is that my tick label and axis label overlap each other. Is there any way to shift the label in all axis far from tick labels? I actually need to keep the tick label font bigger so making that smaller is not an ideal for my case.

推荐答案

几种设置方式

对于所有带有 rcParams 的轴,使用

from matplotlib import rcParams
rcParams['axes.labelpad'] = 20.0

<小时>

单独(对于轴手柄)与


Individually (for an axis handle) with

ax.xaxis.labelpad = 20
ax.yaxis.labelpad = 20
ax.zaxis.labelpad = 20

如果没有轴,可以在此轴之前

if you do not have an axis you can precede this with

ax = plt.gca()

<小时>

创建标签时


When you create the labels

plt.xlabel("X Label", labelpad=20)
plt.ylabel("Y Label", labelpad=20)
plt.zlabel("Z Label", labelpad=20)

或用于轴手柄

ax.set_xlabel("X Label", labelpad=20)
ax.set_ylabel("Y Label", labelpad=20)
ax.set_zlabel("Z Label", labelpad=20)

<小时>

这是一个使用一些随机生成的数据的完整示例


Here is a complete example using some randomly generated data

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import rcParams
rcParams['axes.labelpad'] = 20.0

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

XS = np.random.randn(100)
YS = np.random.randn(100)
ZS = np.random.randn(100)

ax.scatter(XS, YS, ZS, c='r', marker='o')
plt.title("3D Scatterplot")
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()

这篇关于将所有标签值远离轴移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆