严密的Bbox测试

严密的Bbox测试示例

输出:

  1. saving tight_bbox_test.png
  2. saving tight_bbox_test.pdf
  3. saving tight_bbox_test.svg
  4. saving tight_bbox_test.svgz
  5. saving tight_bbox_test.eps
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. ax = plt.axes([0.1, 0.3, 0.5, 0.5])
  4. ax.pcolormesh(np.array([[1, 2], [3, 4]]))
  5. plt.yticks([0.5, 1.5], ["long long tick label",
  6. "tick label"])
  7. plt.ylabel("My y-label")
  8. plt.title("Check saved figures for their bboxes")
  9. for ext in ["png", "pdf", "svg", "svgz", "eps"]:
  10. print("saving tight_bbox_test.%s" % (ext,))
  11. plt.savefig("tight_bbox_test.%s" % (ext,), bbox_inches="tight")
  12. plt.show()

下载这个示例