tight savefig without axes in matplotlib

核能气质少年 提交于 2021-02-11 14:11:05

问题


When using a matplotlib to draw something without axes, savefig() isn't truly "tight":

import matplotlib.pyplot as plt

circ = plt.Circle((0, 0), 1.0)
plt.gca().add_artist(circ)
plt.gca().set_aspect("equal")
plt.axis("off")
# plt.show()
plt.savefig("out.svg", bbox_inches="tight")

That's because the SVG contains the hidden "background patch"

  <g id="patch_1">
   <path d="M 0 280.512 
L 280.512 280.512 
L 280.512 0 
L 0 0 
z
" style="fill:none;"/>
  </g>

How to remove it?


回答1:


pad_inches option!

plt.savefig("out.svg", bbox_inches="tight", pad_inches=0)


来源:https://stackoverflow.com/questions/61712551/tight-savefig-without-axes-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!