How can I send a plt/picture (from matplotlib import pyplot as plt) from Flask to render/show/keep in React?

Viewed 1699

How can I send a plt/picture (from matplotlib import pyplot as plt) from Flask to render/show/keep in React?

I just took the relevant part from python and react, instead of having all the code here.

main.py

plt.savefig("test100.png", transparent=True, bbox_inches='tight', dpi=150) //Here
return send_file('test100.png', mimetype='image/jpg') //Here

kmeans.js

axios.post(`/kmeans`, {
     cart: this.state.cart
}).then(function (response) {
    console.log(response) // Here
})

I was searching online for example, and I found, but seems to be some depreciated methods that does not work anymore (for example, how to get an image from flask api in react native which results in TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided. at KMeansAlgorithm.js:59) . Not sure I am doing it right in flask as well.

0 Answers
Related