我正在使用matplotlib绘制数据集,其中我有一个非常高"的xlabel(这是在TeX中渲染的公式,其中包含一个分数,因此其高度等于几行文本).
I am plotting a dataset using matplotlib where I have an xlabel that is quite "tall" (it's a formula rendered in TeX that contains a fraction and is therefore has the height equivalent of a couple of lines of text).
无论如何,在绘制数字时,公式的底部总是被截断.更改图形大小似乎无济于事,而且我还无法弄清楚如何将x轴向上"移动以为xlabel腾出空间.这样的事情是一个合理的临时解决方案,但是最好的办法是使matplotlib自动识别标签被切开并相应地调整大小.
In any case, the bottom of the formula is always cut off when I draw the figures. Changing figure size doesn't seem to help this, and I haven't been able to figure out how to shift the x-axis "up" to make room for the xlabel. Something like that would be a reasonable temporary solution, but what would be nice would be to have a way to make matplotlib recognize automatically that the label is cut off and resize accordingly.
这是我的意思的示例:
import matplotlib.pyplot as plt plt.figure() plt.ylabel(r'$\ln\left(\frac{x_a-x_b}{x_a-x_c}\right)$') plt.xlabel(r'$\ln\left(\frac{x_a-x_d}{x_a-x_e}\right)$') plt.show()虽然可以看到整个ylabel,但xlabel在底部被切除了.
while you can see the entire ylabel, the xlabel is cut off at the bottom.
在这是机器特定的问题的情况下,我正在使用matplotlib 1.0.0在OSX 10.6.8上运行它
In the case this is a machine-specific problem, I am running this on OSX 10.6.8 with matplotlib 1.0.0
推荐答案使用:
import matplotlib.pyplot as plt plt.gcf().subplots_adjust(bottom=0.15)为标签腾出空间.
自从我给出答案以来,matplotlib添加了 tight_layout() 功能. 所以我建议使用它:
Since i gave the answer, matplotlib has added the tight_layout() function. So i suggest to use it:
plt.tight_layout()应该为xlabel腾出空间.
should make room for the xlabel.
更多推荐
为什么我的matplotlib图中的xlabel被截断了?
发布评论