Python and Matplotlib

In this example we will show you how to integrate our Python code for generating Matplotlib figures into the Python Code block and use the Image Box block to display it.

It is important to keep in mind that the runtime is not CPython but rather Pyodide that behaves slightly different. For this use case please pay attention at the following points (see the code below):

  • use the Agg backend which works fine with inseri-core (please see line 5)
  • save the figure into a binary buffer (using BytesIO standard library) and get its value (please see lines 10-14)

Now the variable res can be defined as a PNG output of our Python Code, and used further as an input in the Image Box block.

is loading …
is loading …

First Published

in

Last Updated

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *