python 调整子图布局_matplotlib中精确调整子图形大小

本文档介绍如何使用Python的matplotlib库在A4纸上创建3x2子图布局,每个子图大小均匀,顶部留出空间用于标题。通过调整参数如`figure.figsize`和使用`tight_layout`实现更紧凑的布局。示例代码展示了如何创建6个子图并保存为PNG,同时探讨了如何进一步控制子图的大小和位置。
摘要由CSDN通过智能技术生成

我在A4纸上绘制一些索引数据,用3x2行列的6幅图像绘制。我已经得到了基本的代码工作,它将这个数据帧数据绘制成以下6个图。在def plot_idx(df,image,key):

# reset the default parameters

plt.rcParams['font.size'] = 8.

plt.rcParams['figure.figsize'] = (8.267, 11.692) #aA paper

fig = plt.figure()

#plot all the 6 figures and save the 3x2 image as png

ax1 = fig.add_subplot(321) # first row first image

#compute all time

alltime = df['Close'].count()

x,y,x_min, y_min, x_max, y_max = min_max(df,alltime)

ax1.plot(x, y,'r')

ax1.plot(x_min,y_min,'o')

ax1.plot(x_max,y_max,'o')

ax1.set_xlabel('year')

ax1.set_ylabel('Index Close')

ax1.set_title(plot_title[-1])

ax1.fill_between(x,y,facecolor='red')

ax1.annotate(y_min, xy=(x_min,y_min), xytext=(x_min,y_min +

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值