I am trying to plot a white ellipse on a coloured (in my case gray) background. Nothing else, so no axis, no white space and no frame. I managed to remove the axis, but there still is a white border around the image.
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Ellipse
ell = Ellipse(xy=np.random.randint(3,7,2),
width=np.random.randint(2,3), height=np.random.randint(4,6),
angle=np.random.rand() * 360,
color='white', fill=True)
fig, ax = plt.subplots(subplot_kw={'aspect': 'equal'})
ell.set_facecolor('white')
ax.add_artist(ell)
ax.set_facecolor((0.5, 0.5, 0.5))
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
fig.savefig("test.png",bbox_inches='tight')
plt.show()
Removing the frame with
fig = plt.figure(frameon=False)
before saving it didn't work either, because it basically removes everything, resulting in an empty image.
I also tried
ax.axis('off')
but that removed the coloured (gray) background.
Any help is highly appreciated, thank you very much.