0

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")

enter image description here

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?

Nico Schlömer
  • 46,467
  • 24
  • 178
  • 218

1 Answers1

1

pad_inches option!

plt.savefig("out.svg", bbox_inches="tight", pad_inches=0)
david
  • 1,171
  • 1
  • 8
  • 20