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?

3
  • Could you try plt.savefig("out.svg", bbox_inches="tight", transparent=True)? Commented May 10, 2020 at 13:31
  • @Sheldore Doesn't work either. Commented May 10, 2020 at 13:48
  • Maybe also set plt.gcf().patch.set_visible(False) before saving? Commented May 10, 2020 at 21:26

1 Answer 1

1

pad_inches option!

plt.savefig("out.svg", bbox_inches="tight", pad_inches=0)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.