I currently have code like the following:
import os
import numpy as np
import pylab
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib.patches import Polygon
import numpy as np
...
# Read my image
img = matplotlib.image.imread(p_image)
# Render it, move the coordinates' origin to the upper left corner
plt.imshow(np.flipud(img), cmap=cm.Greys_r,origin='upper')
# Overlay a polygon
p = Polygon( zip(xs,ys), alpha=0.2)
plt.gca().add_artist(p)
# Save it to disk
plt.savefig(p_image_output)
How can I directly save this figure to disk without rendering it first on the screen? (notice that I would like the figure to keep the properties specified in the three arguments that I pass to imshow
)