简单轴分割器示例1

简单轴分割器示例1

  1. from mpl_toolkits.axes_grid1 import Size, Divider
  2. import matplotlib.pyplot as plt
  3. fig1 = plt.figure(1, (6, 6))
  4. # fixed size in inch
  5. horiz = [Size.Fixed(1.), Size.Fixed(.5), Size.Fixed(1.5),
  6. Size.Fixed(.5)]
  7. vert = [Size.Fixed(1.5), Size.Fixed(.5), Size.Fixed(1.)]
  8. rect = (0.1, 0.1, 0.8, 0.8)
  9. # divide the axes rectangle into grid whose size is specified by horiz * vert
  10. divider = Divider(fig1, rect, horiz, vert, aspect=False)
  11. # the rect parameter will be ignore as we will set axes_locator
  12. ax1 = fig1.add_axes(rect, label="1")
  13. ax2 = fig1.add_axes(rect, label="2")
  14. ax3 = fig1.add_axes(rect, label="3")
  15. ax4 = fig1.add_axes(rect, label="4")
  16. ax1.set_axes_locator(divider.new_locator(nx=0, ny=0))
  17. ax2.set_axes_locator(divider.new_locator(nx=0, ny=2))
  18. ax3.set_axes_locator(divider.new_locator(nx=2, ny=2))
  19. ax4.set_axes_locator(divider.new_locator(nx=2, nx1=4, ny=0))
  20. plt.show()

下载这个示例