使用Python中的Matplotlib缩放y轴

时间:2022-10-19 09:49:49

How to scale the y-axis with Matplotlib? I don't want to change the y-limit, I just want to extend the physical space.

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

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

2 个解决方案

#1


Just use a larger height value when you instantiate the figure:

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

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

Where figsize=(width, height) and defaults to (8, 6). Values are in inches (the dpi keyword arg can be used to define the DPI for the figure, and there's a default value in your matplotlibrc file)

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

For a figure already created, I believe there is a set_size_inches(width, height) method.

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

#2


Use the subplots_adjust function to control the abount of whitespace:

使用subplots_adjust函数来控制空格的重叠:

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

There is an icon on the toolbar to do this interactively with a widget

工具栏上有一个图标,可以与窗口小部件进行交互式操作

#1


Just use a larger height value when you instantiate the figure:

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

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

Where figsize=(width, height) and defaults to (8, 6). Values are in inches (the dpi keyword arg can be used to define the DPI for the figure, and there's a default value in your matplotlibrc file)

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

For a figure already created, I believe there is a set_size_inches(width, height) method.

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

#2


Use the subplots_adjust function to control the abount of whitespace:

使用subplots_adjust函数来控制空格的重叠:

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

There is an icon on the toolbar to do this interactively with a widget

工具栏上有一个图标,可以与窗口小部件进行交互式操作