Matplotlib: get and set axes position Matplotlib: get and set axes position python python

Matplotlib: get and set axes position


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

import matplotlib.pyplot as pltax = 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.