使用Python中的Matplotlib缩放y轴

时间:2008-12-30 23:02:08

标签: python matplotlib

如何使用Matplotlib缩放y轴?我不想改变y限制,我只是想扩展物理空间。

^      ^
|      |
|      |
+----> |
Before +---->
       After

2 个答案:

答案 0 :(得分:8)

在实例化图形时,只需使用更大的高度值:

from pylab import *
x = linspace(0, 10*pi, 2**10)
y = sin(x)
figure(figsize=(5, 10))
plot(x, y)
show()

figsize=(width, height)的位置,默认为(8, 6)。值以英寸为单位(dpi关键字arg可用于定义图中的DPI,并且matplotlibrc文件中有默认值

对于已经创建的图,我相信有set_size_inches(width, height)方法。

答案 1 :(得分:2)

使用subplots_adjust函数来控制空格的删除:

fig.subplots_adust(bottom = 0.05,top = 0.95)

工具栏上有一个图标,可以通过窗口小部件交互式地执行此操作