py-demandimport icon indicating copy to clipboard operation
py-demandimport copied to clipboard

import matplotlib.pyplot as plt doesn't work with demandimport.enabled()

Open Asmageddon opened this issue 2 years ago • 0 comments

I tried all of the following forms:

with demandimport.enabled():
    # Doesn't work at all
    import matplotlib.pyplot as plt
    from matplotlib import pyplot as plt
    from matplotlib import pyplot
    # Works but can't be reassigned to `plt`.
    import matplotlib.pyplot
    plt = matplotlib.pyplot # Throws a huge error
    plt = object.__getattribute__(matplotlib, "pyplot") # '_demandmod' object has no attribute 'pyplot'

The only form that actually worked was:

with demandimport.enabled():
    import matplotlib.pyplot
plt = matplotlib.pyplot

type(plt) # demandimport._demandmod

Asmageddon avatar Jun 20 '23 10:06 Asmageddon