I am drawing shapes using matplotlib, like that
import matplotlib.pyplot as plt
import matplotlib.patches as patches
fig, ax = plt.subplots(figsize=(4, 4))
ax.tick_params(
axis = 'both',
which = 'both',
bottom = False,
top = False,
left = False,
right = False,
labelbottom = False,
labelleft = False
)
ax.patch.set_facecolor('#FFFF99')
ax.add_patch(patches.Rectangle((0.1, 0.1), 0.3, 0.2,
facecolor = "green", edgecolor = "black"))
ax.add_patch(patches.Circle((0.5, 0.5), radius = 0.05, facecolor="blue"))
fig.savefig("test.png", bbox_inches='tight')
What I get is
The shapes are good, but there is white border outside of the region where I draw shapes; it is not seen on the white background, but it is there.
The question is: How to get rid of this white outer border in the saved file? bbox_inches='tight'
does not help.
PS: fig.savefig("test.png", bbox_inches='tight', pad_inches = 0)
does the job. Unfortunately it is sort of "too tight", because now I lost bottom and right parts of the axes frame,
Probably matplotlib bug (I am using version 3.1.3)