如何使用子块更改图形大小?

2024-04-25 19:32:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Matplotlib网站上看到了this example。我想知道是否有可能增加体型。

我试过了

f.figsize(15,15)

但它什么也做不了。


Tags: matplotlib网站examplethisfigsize体型
2条回答

或者,使用figsize参数创建figure()对象,然后使用add_subplot添加子块。E、 g

import matplotlib.pyplot as plt
import numpy as np

f = plt.figure(figsize=(10,3))
ax = f.add_subplot(121)
ax2 = f.add_subplot(122)
x = np.linspace(0,4,1000)
ax.plot(x, np.sin(x))
ax2.plot(x, np.cos(x), 'r:')

Simple Example

这种方法的好处是语法更接近于subplot()的调用,而不是subplots()。E、 子块似乎不支持使用GridSpec来控制子块的间距,但是subplot()add_subplot()都支持。

如果您已经使用figure对象:

f.set_figheight(15)
f.set_figwidth(15)

但是,如果您使用.subplots()命令(如您所示的示例)创建一个新图形,您还可以使用:

f, axs = plt.subplots(2,2,figsize=(15,15))

相关问题 更多 >