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?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249

1 Answers1

1

pad_inches option!

plt.savefig("out.svg", bbox_inches="tight", pad_inches=0)
david
  • 1,302
  • 1
  • 10
  • 21