Python/Matplotlib - Change the relative size of a subplot

后端 未结 3 1623
盖世英雄少女心
盖世英雄少女心 2020-12-13 13:38

I have two plots

import matplotlib.pyplot as plt
plt.subplot(121)
plt.subplot(122)

I want plt.subplot(122) to be half as wide

3条回答
  •  無奈伤痛
    2020-12-13 14:16

    See the grid-spec tutorial:

    http://matplotlib.sourceforge.net/users/gridspec.html

    Example code:

    import matplotlib.pyplot as plt
    import matplotlib.gridspec as gridspec
    
    f = plt.figure()
    
    gs = gridspec.GridSpec(1, 2,width_ratios=[2,1])
    
    ax1 = plt.subplot(gs[0])
    ax2 = plt.subplot(gs[1])
    
    plt.show()
    

    You can also adjust the height ratio using a similar option in GridSpec

提交回复
热议问题