This might not be the best MWE but I'm not sure if this is a specific problem or if I just don't know basic things. This works:
import matplotlib as mpl
import matplotlib.backends.backend_tkcairo as tkcairo
fig = mpl.figure.Figure()
canvas = tkcairo.FigureCanvasTkCairo(fig)
and I thought that this should work, too:
import matplotlib as mpl
fig = mpl.figure.Figure()
canvas = mpl.backends.backend_tkcairo.FigureCanvasTkCairo(fig)
But it doesn't (module 'matplotlib' has no attribute 'figure'). Why doesn't this work, and why is the error relating to mpl.figure.Figure(), which does not differ between the two MWEs?
CodePudding user response:
matplotlib does not automatically import submodule figure or submodule backends, but backends.backend_tkcairo imports figure.
Just importing a module doesn't mean necessarily that all submodules come along for the ride. It depends on how these are written.
In this case, it's best to import explicitly the submodules you need.
