演示固定尺寸轴

演示固定尺寸轴

演示固定尺寸轴2

  1. import matplotlib.pyplot as plt
  2. from mpl_toolkits.axes_grid1 import Divider, Size
  3. from mpl_toolkits.axes_grid1.mpl_axes import Axes
  4. def demo_fixed_size_axes():
  5. fig1 = plt.figure(1, (6, 6))
  6. # The first items are for padding and the second items are for the axes.
  7. # sizes are in inch.
  8. h = [Size.Fixed(1.0), Size.Fixed(4.5)]
  9. v = [Size.Fixed(0.7), Size.Fixed(5.)]
  10. divider = Divider(fig1, (0.0, 0.0, 1., 1.), h, v, aspect=False)
  11. # the width and height of the rectangle is ignored.
  12. ax = Axes(fig1, divider.get_position())
  13. ax.set_axes_locator(divider.new_locator(nx=1, ny=1))
  14. fig1.add_axes(ax)
  15. ax.plot([1, 2, 3])
  16. def demo_fixed_pad_axes():
  17. fig = plt.figure(2, (6, 6))
  18. # The first & third items are for padding and the second items are for the
  19. # axes. Sizes are in inches.
  20. h = [Size.Fixed(1.0), Size.Scaled(1.), Size.Fixed(.2)]
  21. v = [Size.Fixed(0.7), Size.Scaled(1.), Size.Fixed(.5)]
  22. divider = Divider(fig, (0.0, 0.0, 1., 1.), h, v, aspect=False)
  23. # the width and height of the rectangle is ignored.
  24. ax = Axes(fig, divider.get_position())
  25. ax.set_axes_locator(divider.new_locator(nx=1, ny=1))
  26. fig.add_axes(ax)
  27. ax.plot([1, 2, 3])
  28. if __name__ == "__main__":
  29. demo_fixed_size_axes()
  30. demo_fixed_pad_axes()
  31. plt.show()

下载这个示例