使用 LaTeX 标签时,Matplotlib mplot3d 标签和刻度重叠

问题描述 投票:0回答:2

使用 matplotlib 3d 绘图时如何避免标签和刻度线重叠?

下面的代码生成一个 matplotlib 图形。该图显示了在标签中使用 LaTeX 时标签填充和 3D 绘图的问题。 (也许有足够权限的人可以贴出相应的图)

如果标签中不使用 LaTeX,有一个解决方案: 调整matplotlib Axes3D中的标签位置

如果您使用 LaTeX 来渲染标签,那么 开头被忽略(或产生错误)! 我已经尝试了很多从 \phantom 和 space*,从 \mbox 到 minipage,但它不起作用! mplot3d + x,y,zlabel + LaTeX 有什么解决方案吗

在 mplot3d API 文档(http://matplotlib.org/mpl_toolkits/mplot3d/api.html)中提到,参数 labelpad 未实现 jet '目前,labelpad 对标签没有影响。' .

示例:

import matplotlib.pyplot as pyplot  
import mpl_toolkits.mplot3d

from matplotlib.pyplot import rc  
rc('text', usetex = True)  
rc('font', size=9, family='serif', serif='Times')

fig = pyplot.figure(figsize=(8/2.5, 5/2.5))  
ax = fig.gca(projection='3d')

plot = ax.plot([.1,.2,.3],[.1,.2,.3])

xLabel = ax.set_xlabel('XxxXxxX')  
yLabel = ax.set_ylabel('YyyYyyY')  
zLabel = ax.set_zlabel('ZzzZzzZ')  # \n in here produces an error or is ignored see below   

pyplot.show()   

... 我尝试过的事情:
ax.set_ylabel(r"\phantom{x}" " " r'ABC', 行距=-0.5)

3d matplotlib latex label padding
2个回答
2
投票

我通过向下滚动找到了解决方案:调整 matplotlib 的 Axes3D 中的标签位置

只需添加:

ax.xaxis._axinfo['label']['space_factor'] = 2.0
ax.yaxis._axinfo['label']['space_factor'] = 2.0
ax.zaxis._axinfo['label']['space_factor'] = 2.0

这是唯一对我有用的解决方案。


0
投票

使用 ' ' 调整标签本身。

尝试

xLabel = ax.set_xlabel('\n\nXxxXxxX')  
yLabel = ax.set_ylabel('\n\nYyyYyyY')  
zLabel = ax.set_zlabel('\n\nZzzZzzZ') 
© www.soinside.com 2019 - 2024. All rights reserved.