From Flask, How To Send The Matplotlib Plot Image Into Json Object?
We are trying to create an API that works with React on the frontend and Flask on the backend. As a part of this, the output that needs to be displayed includes four entities: 2 im
Solution 1:
Assuming you have your plot looking the way you'd like, you can always base64 encode the file it's stored in and reproduce it on another machine. Take a look:
# assume your plot is saved to tfilewithopen(tfile) as fin:
read_in = fin.read()
b64_data = base64.urlsafe_b64encode(read_in.decode('utf-8'))
# now send over the network
Solution 2:
https://github.com/mpld3/mpld3 mpld3 provides a custom stand-alone javascript library built on D3, which parses JSON representations of plots. The mpld3 python module provides a set of routines which parses matplotlib plots (using the mplexporter framework) and outputs the JSON description readable by mpld3.js.
Post a Comment for "From Flask, How To Send The Matplotlib Plot Image Into Json Object?"