How to use `GridSpec()` with `subplots()`

前端 未结 1 2010
遇见更好的自我
遇见更好的自我 2020-12-25 11:54

There are several (example) SO posts dealing with how to use GridSpec with subplotting in general. What i am trying to achieve to no avail, is to allow the use

相关标签:
1条回答
  • 2020-12-25 12:47

    Rather than calling gridspec.GridSpec before subplots, you can send the kwargs to GridSpec from within your subplots call, using the gridspec_kw argument. From the docs:

    gridspec_kw : dict

    Dict with keywords passed to the GridSpec constructor used to create the grid the subplots are placed on.

    So, for example:

    import matplotlib.pyplot as plt
    
    tPlot, axes = plt.subplots(
            nrows=4, ncols=1, sharex=True, sharey=False, 
            gridspec_kw={'height_ratios':[2,2,1,1]}
            )
    
    tPlot.suptitle('node', fontsize=20)
    
    axes[0].plot(range(10),'ro-') 
    axes[1].plot(range(10),'bo-') 
    axes[2].plot(range(10),'go-') 
    axes[3].plot(range(10),'mo-') 
    
    plt.show()
    

    0 讨论(0)
提交回复
热议问题