Plot functions shoud return the matplolib figure to make it possible to store the figure

It would be great if all “plot functions”, i.e. all functions that generate a matplotlib plots, returned the figure, so that is easy to save the figure.

If you don’t use fastai from a notebook but from within a script you have to save the plots one generates manually, e.g. save the lr_find plot or the data.show_batch plot. Currently that is not possible though.

I don’t know the best way without breaking the current API. In my plotting function I normally pass an axis object to the function (if the object is None the axis object is created in the function).

5 Likes

+10 to this. Every time I come across a package that makes plots and doesn’t return them I die a little inside. Perhaps there is a good reason not to do it, but I almost always inevitably want to manipulate something about the plots either for my own readability, further analysis, or to style them for publication.

I’m with you

In the meantime I overwrote the relevant functions of the ClassificationInterpretation because that is what I constantly want to store.

Here is my code https://github.com/sotte/fastai/commit/2240fd017dab2da5ca2fd0f77bf72d9ad15ebc6a
The changes are trivial.

I could create a PR. @sgugger what do you think?

It sounds useful too, thanks!

Here we go: https://github.com/fastai/fastai/pull/1725