调整标签定位在matplotlib的Axes3D [英] Adjust label positioning in Axes3D of matplotlib

查看:1031
本文介绍了调整标签定位在matplotlib的Axes3D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有轴标签重叠蜱标签在matplotlib麻烦。我试图通过应用转换或致电set_y()手动重新定位的标签,但无济于事。

I am having trouble with axes labels overlapping ticks labels in matplotlib. I've tried to reposition the labels "manually" by applying transforms or by calling set_y(), but no avail.

下面是一个片段,重现该问题:

Here's a snippet that reproduces the problem:

import matplotlib
matplotlib.use("TKAGG")
import matplotlib.pyplot as pyplot
import mpl_toolkits.mplot3d

figure = pyplot.figure()
figure.subplots_adjust(bottom=0.25, top=0.75)
axes = figure.gca(projection='3d')
xLabel = axes.set_xlabel('XXX xxxxxx xxxx x xx x')
yLabel = axes.set_ylabel('YY (y) yyyyyy')
zLabel = axes.set_zlabel('Z zzzz zzz (z)')
plot = axes.plot([1,2,3],[1,2,3])

pyplot.show()

请注意如何x和y的标签发生冲突的蜱。我可以解决这个优雅?

Note how the x and y labels clash with the ticks. Can I solve this elegantly ?

推荐答案

我分享你的无奈。我的工作是一个良好的半小时,毫无进展。该文档说set_xlabel需要一个ARG <一href="http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.set_xlabel">labelpad但我得到一个错误(AttributeError异常:未知的属性labelpad)!事后设置它不会做任何事情,在x轴或w_xaxis。

I share your frustration. I worked on it for a good half hour and got nowhere. The docs say set_xlabel takes an arg labelpad but I get an error (AttributeError: Unknown property labelpad)! Setting it after the fact doesn't do anything, on xaxis or w_xaxis.

下面是一个粗糙的解决方法:

Here's a crude workaround:

import matplotlib
matplotlib.use("TKAGG")
import matplotlib.pyplot as pyplot
import mpl_toolkits.mplot3d

figure = pyplot.figure(figsize=(8,4), facecolor='w')
ax = figure.gca(projection='3d')

xLabel = ax.set_xlabel('\nXXX xxxxxx xxxx x xx x', linespacing=3.2)
yLabel = ax.set_ylabel('\nYY (y) yyyyyy', linespacing=3.1)
zLabel = ax.set_zlabel('\nZ zzzz zzz (z)', linespacing=3.4)
plot = ax.plot([1,2,3],[1,2,3])
ax.dist = 10

pyplot.show()

这篇关于调整标签定位在matplotlib的Axes3D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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