Multiple titles (suptitle) with subplots

前端 未结 1 1183
走了就别回头了
走了就别回头了 2021-01-14 17:56

I have a series of 9 subplots in a 3x3 grid, each subplot with a title. I want to add a title for each row. To do so I thought about using suptitle. The problem is if I use

相关标签:
1条回答
  • 2021-01-14 18:25

    You can tinker with the titles and labels. Check the following example adapted from your code:

    import matplotlib.pyplot as plt
    
    fig, axes = plt.subplots(3,3,sharex='col', sharey='row')
    
    counter = 0
    for j in range(9):
        if j in [0,3,6]:
            axes.flat[j].set_ylabel('Row '+str(counter), rotation=0, size='large',labelpad=40)
            axes.flat[j].set_title('plot '+str(j))
            counter = counter + 1
        if j in [0,1,2]:
            axes.flat[j].set_title('Column '+str(j)+'\n\nplot '+str(j))
        else:
            axes.flat[j].set_title('plot '+str(j))
    
    plt.show()
    

    , which results in:

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