修补效果演示

修补效果演示

  1. import matplotlib.pyplot as plt
  2. import matplotlib.patheffects as PathEffects
  3. import numpy as np
  4. if 1:
  5. plt.figure(1, figsize=(8, 3))
  6. ax1 = plt.subplot(131)
  7. ax1.imshow([[1, 2], [2, 3]])
  8. txt = ax1.annotate("test", (1., 1.), (0., 0),
  9. arrowprops=dict(arrowstyle="->",
  10. connectionstyle="angle3", lw=2),
  11. size=20, ha="center",
  12. path_effects=[PathEffects.withStroke(linewidth=3,
  13. foreground="w")])
  14. txt.arrow_patch.set_path_effects([
  15. PathEffects.Stroke(linewidth=5, foreground="w"),
  16. PathEffects.Normal()])
  17. pe = [PathEffects.withStroke(linewidth=3,
  18. foreground="w")]
  19. ax1.grid(True, linestyle="-", path_effects=pe)
  20. ax2 = plt.subplot(132)
  21. arr = np.arange(25).reshape((5, 5))
  22. ax2.imshow(arr)
  23. cntr = ax2.contour(arr, colors="k")
  24. plt.setp(cntr.collections, path_effects=[
  25. PathEffects.withStroke(linewidth=3, foreground="w")])
  26. clbls = ax2.clabel(cntr, fmt="%2.0f", use_clabeltext=True)
  27. plt.setp(clbls, path_effects=[
  28. PathEffects.withStroke(linewidth=3, foreground="w")])
  29. # shadow as a path effect
  30. ax3 = plt.subplot(133)
  31. p1, = ax3.plot([0, 1], [0, 1])
  32. leg = ax3.legend([p1], ["Line 1"], fancybox=True, loc='upper left')
  33. leg.legendPatch.set_path_effects([PathEffects.withSimplePatchShadow()])
  34. plt.show()

下载这个示例