锚定Box04

锚定Box04示例

  1. from matplotlib.patches import Ellipse
  2. import matplotlib.pyplot as plt
  3. from matplotlib.offsetbox import (AnchoredOffsetbox, DrawingArea, HPacker,
  4. TextArea)
  5. fig, ax = plt.subplots(figsize=(3, 3))
  6. box1 = TextArea(" Test : ", textprops=dict(color="k"))
  7. box2 = DrawingArea(60, 20, 0, 0)
  8. el1 = Ellipse((10, 10), width=16, height=5, angle=30, fc="r")
  9. el2 = Ellipse((30, 10), width=16, height=5, angle=170, fc="g")
  10. el3 = Ellipse((50, 10), width=16, height=5, angle=230, fc="b")
  11. box2.add_artist(el1)
  12. box2.add_artist(el2)
  13. box2.add_artist(el3)
  14. box = HPacker(children=[box1, box2],
  15. align="center",
  16. pad=0, sep=5)
  17. anchored_box = AnchoredOffsetbox(loc='lower left',
  18. child=box, pad=0.,
  19. frameon=True,
  20. bbox_to_anchor=(0., 1.02),
  21. bbox_transform=ax.transAxes,
  22. borderpad=0.,
  23. )
  24. ax.add_artist(anchored_box)
  25. fig.subplots_adjust(top=0.8)
  26. plt.show()

下载这个示例