I read some of the related issues for avoiding warning "Adding an axes using the same arguments as previous axes currently reuses the earlier instance." but I could not apply it in the code below:
The code below generates 10 rectangles which each rectangle has a different color on its edges, coord is an array with size [5,2,10] which contains the coordinates of 10 rectangles.
import matplotlib.pyplot as plt
pixels = 600
my_dpi = 100
num_geo=5
for i in range(10):
fig = plt.figure(num_geo,figsize=( pixels/my_dpi, pixels/my_dpi),facecolor='k', dpi=my_dpi)
plt.axes([0,0,1,1])
rectangle = plt.Rectangle((-300, -300), 600, 600, fc='k')
plt.gca().add_patch(rectangle)
plt.plot([coord[0][0][i], coord[4][0][i]], [coord[0][1][i], coord[4][1][i]], color=str(a1), lw=8, antialiased=True)
plt.axis('off')
plt.axis([-300,300,-300,300])
plt.savefig('fig/%d.png' % i, dpi=my_dpi)
plt.close()