matplotlib-pyodide icon indicating copy to clipboard operation
matplotlib-pyodide copied to clipboard

Matplotlib web assembly backend causes failures in webworker

Open SimonBiggs opened this issue 6 years ago • 3 comments

Matplotlib tries to run from js import document. This causes an exception when Pyodide is being run from within a webworker.

SimonBiggs avatar May 25 '19 13:05 SimonBiggs

The wasm backend wouldn't work in a webworker because it requires the DOM. However, running data-only backends in matplotlib seems useful and desirable.

Is this also true if you do

import matplotlib
matplotlib.use('Agg')

?

mdboom avatar Jun 04 '19 18:06 mdboom

Unfortunately I couldn't actually test that as when I tried to change the backend I ran into https://github.com/iodide-project/pyodide/issues/441

That issue certainly was not matplotlib specific. I initially bumped into it running my own code, but I chose matplotlib just as an example that removes as much extra complications out of it...

SimonBiggs avatar Jun 04 '19 20:06 SimonBiggs

I also recently encountered this problem and matplotlib.use() (as suggested in https://github.com/iodide-project/pyodide/issues/442#issuecomment-498784449) doesn't work because the backend has to be set before the matplotlib import.

The following approach -overriding the MPLBACKEND env var right up front- appears to work:

import os
os.environ['MPLBACKEND'] = 'AGG'

# keep calm & carry on as usual e.g.:
import matplotlib as mpl

worrel avatar May 04 '20 15:05 worrel