0

I have a jupyter notebook with multiple cells, many of which produce a figure with matplotlib.

In the end of my notebook, I would like to create a figure with multiple subplots which are exact copies of the previous plots, in order to save it into a single file.

What I tried to do (and does not work) is copying the previous axes objects):

fig, newax = plt.subplots(2,1)
newax[0]=prevax0
newax[1]=prevax1
plt.show()

It just shows empty figures, apparently copying axes does not work.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Skeksis
  • 9
  • 1
  • There's several approaches and aspects that make your question rather an open one. Part of your questions about recalling the figures. You usually can recall the figure object produced in later cells, if you assign the figure object to variabe. Is that what you really want? I think what you really are after is make a composite figure later as a sort of report? That is potentially independent of what you describe because it can be done more simply. One direct way is to save the figure objects of the plots as image files and then composite then together with pillow or pdfreport. ... – Wayne Mar 23 '23 at 14:49
  • Then there are other more general ways to just do the collecting of the outputs of the cells, including plots. You may want to look at [Scrapbook](https://github.com/nteract/scrapbook) and [nbgather](https://github.com/microsoft/gather) for collecting code and associated output. Getting back to recalling plots again later, it depends on exactly what type of object it is so that sometimes you use the variable name with `.figure` or `.fig` or the subplot variable. For examples, see very first paragraph [here](https://stackoverflow.com/a/60157495/8508004), ... – Wayne Mar 23 '23 at 15:01
  • [here](https://stackoverflow.com/a/36267710/8508004), and the top section [here](https://stackoverflow.com/a/60269307/8508004). But those handles don't give you much of a handle to arranging them unless you tie them in with a table or something, taking advantage of using HTML in a cell output. Plus there are more complex options, using HBox and Vbox, see [here](https://stackoverflow.com/a/72722172/8508004) and references, therein. Hopefully that gives you an idea of how open ended what you asked really is and gives you some options to think about. – Wayne Mar 23 '23 at 15:07

0 Answers0