plotter: import pyplot if not available
Since importing pyplot
has side-effects, we may not import it when importing kwant
.
Currently we instruct the users to import pyplot, but this is counter-intuitive. Since users expect to get some plot when calling the plotting functions the users expect a result, I believe we should just go ahead and importing pyplot without being asked.
Below I list possible usage scenarios and the expected outcomes.
- User imports kwant, then selects mpl backend, calls kwant plot. Expected result: plot is produced with expected backend.
- User selects mpl backend, then imports kwant, calls kwant plot. Expected result: plot is produced with expected backend
- User imports kwant, doesn't select any backend, calls kwant plot. Expected result: some plot is produced. Current result: user is asked to import pyplot explicitly.
I believe we can improve the problem in 3. by importing pyplot within the output_fig
function. This will not alter the above two use cases, and it is acceptable that calling Kwant functions has side-effects.
This is trivial to implement, but I'd like @cwg's approval first.