Changing matplotlib subplot size/position after axes creation

前端 未结 3 1414
难免孤独
难免孤独 2021-02-04 01:05

Is it possible to set the size/position of a matplotlib subplot after the axes are created? I know that I can do:

import matplotlib.pyplot as plt

ax = plt.subp         


        
3条回答
  •  天涯浪人
    2021-02-04 01:58

    You can create a figure with one subplot that spans two rows and one subplot that spans one row using the rowspan argument to subplot2grid:

    import matplotlib.pyplot as plt
    
    fig = plt.figure()
    ax1 = plt.subplot2grid((3,1), (0,0), rowspan=2)
    ax2 = plt.subplot2grid((3,1), (2,0))
    plt.show()
    

    enter image description here

    If you want to change the subplot size and position after it's been created you can use the set_position method.

    ax1.set_position([0.1,0.1, 0.5, 0.5])
    

    Bu you don't need this to create the figure you described.

提交回复
热议问题