Findobj演示

递归查找符合某些条件的所有对象

Findobj演示

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import matplotlib.text as text
  4. a = np.arange(0, 3, .02)
  5. b = np.arange(0, 3, .02)
  6. c = np.exp(a)
  7. d = c[::-1]
  8. fig, ax = plt.subplots()
  9. plt.plot(a, c, 'k--', a, d, 'k:', a, c + d, 'k')
  10. plt.legend(('Model length', 'Data length', 'Total message length'),
  11. loc='upper center', shadow=True)
  12. plt.ylim([-1, 20])
  13. plt.grid(False)
  14. plt.xlabel('Model complexity --->')
  15. plt.ylabel('Message length --->')
  16. plt.title('Minimum Message Length')
  17. # match on arbitrary function
  18. def myfunc(x):
  19. return hasattr(x, 'set_color') and not hasattr(x, 'set_facecolor')
  20. for o in fig.findobj(myfunc):
  21. o.set_color('blue')
  22. # match on class instances
  23. for o in fig.findobj(text.Text):
  24. o.set_fontstyle('italic')
  25. plt.show()

下载这个示例