I need to draw figure subtitles through loop iterations; each iteration calls a function defined in another module (= another py file) that draws a pair of subheadings. Here is what I tried - and alas, it does not work:
1) Before the loop, create a shape with enough rows and two columns:
import matplotlib.pyplot as plt fig, axarr = plt.subplots(nber_rows,2)
2) Inside the loop on the iter_nber iteration number, call the function that draws each subheading:
fig, axarr = module.graph_function(fig,axarr,iter_nber,some_parameters, some_data)
3) This function is basically like this; each iteration creates a pair of subheadings in one line:
def graph_function(fig,axarr,iter_nber,some_parameters, some_data): axarr[iter_nber,1].plot(--some plotting 1--) axarr[iter_nber,2].plot(--some plotting 2--) return fig,axarr
This does not work. I end up with an empty figure at the end of the loop. I tried various combinations above, for example, leaving only axarr in the return argument of the function, but to no avail. Obviously, I do not understand the logic of this figure and its subplots.
Any suggestions that are very much appreciated.
python matplotlib subplot
Charles
source share