简体   繁体   English

matplotlib 中没有轴的紧凑保存图

[英]tight savefig without axes in matplotlib

When using a matplotlib to draw something without axes, savefig() isn't truly "tight":当使用 matplotlib 绘制没有轴的东西时, savefig()并不是真正的“紧”:

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"那是因为 SVG 包含隐藏的“背景补丁”

  <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?如何删除它?

pad_inches option! pad_inches选项!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM