簡體   English   中英

在matplotlib中設置子圖的大小

[英]Set size of subplot in matplotlib

我想知道當圖包含多個子圖(在我的情況下為5×2)時如何設置子圖的大小。 無論我允許整個人物有多大,子圖總是看起來很小。 我希望能直接控制該圖中子圖的大小。 代碼的簡化版本粘貼在下面。

import numpy as np
import matplotlib.pyplot as plt

x = np.random.randn(20)
y = np.random.randn(20)

fig = plt.figure(figsize=(20, 8))

for i in range(0,10):
    ax = fig.add_subplot(5, 2, i+1)
    plt.plot(x, y, 'o')
    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)
    # x and y axis should be equal length
    x0,x1 = ax.get_xlim()
    y0,y1 = ax.get_ylim()
    ax.set_aspect(abs(x1-x0)/abs(y1-y0))

plt.show()
fig.savefig('plot.pdf', bbox_inches='tight')

只需切換圖形尺寸寬度和高度:

fig = plt.figure(figsize=(20, 8))

至:

fig = plt.figure(figsize=(8, 20))

使用整個頁面為你的情節。

這將改變你的情節:

在此輸入圖像描述

至:

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM