I keep receiving the following warning:
RuntimeWarning: 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcP ││ `figure.max_open_warning`).
Here is the part of my code that uses matplotlib. Note that I am using flask to generate an image to display.
import matplotlib.pyplot as plt
...
fig, ax = plt.subplots()
plt.imshow(plot_data, extent=[0, max_distance, y_lims[0], y_lims[1]],cmap=cmap, origin='lower', norm=Normalize(-20, 75),aspect=300)
ax.yaxis_date()
...
ax.yaxis.set_major_formatter(yfmt)
ax.yaxis.set_major_locator( mdates.HourLocator(interval = 1))
plt.grid(b=True, which='major', color='#666666', linestyle='-')
figdata = BytesIO()
fig.tight_layout()
fig.savefig(figdata, format='png')
plt.close(fig)
# Return image
resp = Response(figdata.getvalue(), mimetype='image/png')
The code only runs once so I do not understand why I would get the error.