0

I'm currently running a loop that exports a 2 column, 1 row subplot (initial state, final state where initial_state needs to have a circle patch and an arrow drawn.) on each iteration but I'd like to have a way of, when that loop ends, show on a big plot all the previous subplots together on a 2 column, N row subplot. Is there a way to "save" previous plots and then "append them" on the new figure once the loop ends?

I was looking for something in the sorts of:

initials = []
finals = []

while done == False:
    fig, (initial_state,final_state) = plt.subplots(1,2)
    initial_state.imshow(initial_state_data)
    initial_state.add_patch(circle)
    initial_state.arrow(arrow_parameters)
    initial_state.set_title('Title 1')
    final_state.imshow(final_state_data)
    final_state.set_title('Title 2')

    initials.append(initial_state)
    finals.append(final_state)

fig2,big_plots = plt.subplot(n,2) #n is the number of iterations in this case
for i in range(n):
    big_plots[i,0] = initials[i]
    big_plots[i,1] = finals[i]

Of course, I'm pretty sure that appending plots to a list is not going to work, but I feel like that's the easiest way to explain what I needed.

This seems like a simple enough thing to do, but I've been looking for days and couldn't find anything.

Mad Man
  • 27
  • 1
  • 1
    [Copying axis objects is non-trivial.](https://stackoverflow.com/a/45812071/8881141) – Mr. T Feb 21 '22 at 10:13
  • The highly recommended way, is to create a function that gets an `ax` as parameter and creates the desired subplot again onto that `ax`. – JohanC Feb 21 '22 at 12:18
  • What happens to the figures in the while loop? Do you save them, show them with `plt.show()`, something else? – Mr. T Feb 21 '22 at 13:51
  • Does this mean that the value of n is not known in advance? In this case, I recommend you to use [patchworklib](https://github.com/ponnhide/patchworklib). Using this, you can arrange any number of subplots without deciding their layout in advance. – Hideto Feb 22 '22 at 18:14

0 Answers0