Matplotlib: get and set axes position

前端 未结 1 1240
囚心锁ツ
囚心锁ツ 2020-12-30 01:25

In matlab, it\'s straightforward to get and set the position of an existing axes on the figure:

  pos = get(gca(), \'position\')
  set(gca(), \'position\', p         


        
相关标签:
1条回答
  • 2020-12-30 01:52

    Setting axes position is similar in Matplotlib. You can use the get_position and set_position methods of the axes.

    import matplotlib.pyplot as plt
    
    ax = plt.subplot(111)
    pos1 = ax.get_position() # get the original position 
    pos2 = [pos1.x0 + 0.3, pos1.y0 + 0.3,  pos1.width / 2.0, pos1.height / 2.0] 
    ax.set_position(pos2) # set a new position
    

    You might also want to take a look at GridSpec if you haven't already.

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