mardi 6 juillet 2021

Return Figure in FastAPI

Im trying to return a matplotlib.figure.Figure in FastAPI. If I save it like an image it works (code here):

@router.get("/graph/{id_file}", name="Return the graph obtained")
async def create_graph(id_file: str):
        data = HAR.createGraph(id_file)
        graph = HAR.scatterplot(data['dateTimes'], data['label'], "Time", "Activity")
        graph.savefig('saved_figure.jpg')
        
        return FileResponse('saved_figure.jpg')

Where graph is my Figure. But I would like to show it without saving in mi computer.




Aucun commentaire:

Enregistrer un commentaire