Usually you do something like this:
def create_subplot(data, ax=None): if ax is None: ax = plt.gca() more_data = do_something_on_data() bp = ax.boxplot(more_data) return bp
You do not "return the plot from the function and use it as a subtitle." Instead, you need to plot a square on the axes in the subtitle.
The if ax is None is there, so the transfer in explicit axes is optional (if not, the current piping axes identical to the calling plt.boxplot will be used.). If you prefer, you can leave it and ask for specific axes.
Joe kington
source share