I am using a package called matplotlib to create some graphs, based on user input. Creating these graphs can be done like so
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
some_plot = plt.figure()
Moreover it is possible to then save these graphs as images,
some_plot.savefig(path, format='png')
The problem is that I don't really want to save every single user generated graph, but rather I would like to just display them. I have tried to look up some solutions for related problems. One such solution was to use IoBytes. Following along these answer I get something like
from io import BytesIO
some_plot_io = BytesIO()
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
some_plot = plt.figure()
some_plot.savefig(some_plot_io, format='png')
Is it possible to somehow pass on the BytesIO object to the template and serve the image or does this method not work? Would there be some other method to do this?