Python Pylab,如何更改标签大小以指定轴的大小 [英] Python Pylab, how to alter the size of the label specifying the magnitude of the axes

查看:91
本文介绍了Python Pylab,如何更改标签大小以指定轴的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图绘制核衰变的不同横截面,因此y轴的大小在10^-38 (m^2) pylab周围,默认情况下将轴绘制为0.0,0.2,0.4...等,并且在'1e-38'的顶部y轴.

I am attempting to plot differential cross-sections of nuclear decays and so the magnitudes of the y-axis are around 10^-38 (m^2) pylab as default plots the axis as 0.0,0.2,0.4... etc and has a '1e-38' at the top of the y-axis.

我只需要增加一点字体大小,我已经尝试过调整标签大小

I need to increase the font size of just this little bit, I have tried adjusting the label size

py.tick_params(axis='y', labelsize=20)

但这只会调整标签0.0,0.2,0.4....

非常感谢您的所有帮助

推荐答案

您可以使用 ax.yaxis.get_offset_text() .

You can access the text object using the ax.yaxis.get_offset_text().

import numpy as np
import matplotlib.pyplot as plt

# Generate some data
N = 10
x = np.arange(N)
y = np.array([i*(10**-38) for i in x])

fig, ax = plt.subplots()

# Plot the data
ax.plot(x,y)

# Get the text object
text = ax.yaxis.get_offset_text()

# Set the size.
text.set_size(30) # Overkill!

plt.show()

我已经使用matplotlib.pyplot而不是pylab编写了上面的解决方案,但是如果您绝对必须使用pylab,则可以更改它(尽管我建议您使用matplotlib.pyplot,因为它们几乎相同可以用pyplot轻松完成更多工作).

I've written the solution above using matplotlib.pyplot rather than pylab though if you absolutely have to use pylab then it can be changed (though I'd recommend you use matplotlib.pyplot in any case as they are pretty much identical you can just do a lot more with pyplot easier).

如果要使用pylab,则代码为:

If you were to use pylab then the code would be:

pylab.plot(x, y)

ax = pylab.gca() # Gets the current axis object

text = ax.yaxis.get_offset_text() # Get the text object

text.set_size(30) # # Set the size.

pylab.show()

带有(过度杀伤!)偏移文本的示例情节.

这篇关于Python Pylab,如何更改标签大小以指定轴的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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