32

I have functions that contribute to small parts of a figure generation. I'm trying to use these functions to generate multiple figures? So something like this:

  1. work with Figure 1
  2. do something else
  3. work with Figure 2
  4. do something else
  5. work with Figure 1
  6. do something else
  7. work with Figure 2

If anyone could help, that'd be great!

3 Answers 3

35

There are several ways to do this, and the simplest is to use the figure numbers. The code below makes two figures, #0 and #1, each with two lines. #0 has the points 1,2,3,4,5,6, and #2 has the points 10,20,30,40,50,60.

from pylab import *

figure(0)
plot([1,2,3])

figure(1)
plot([10, 20, 30])

figure(0)
plot([4, 5, 6])

figure(1)
plot([40, 50, 60])

show()
Sign up to request clarification or add additional context in comments.

5 Comments

That's the pylab "state machine" style interface. A better option for serious software development is to use the object-oriented way where you have figure objects containing axes objects whose plot methods you call. But the pylab approach is much simpler for interactive command-line usage.
Ah ha! But the second time you refer to the figure, you don't need to use the "ax" variables?
I have a follow up question here
@aspade - the "ax" variable were superfluous, so I've removed them. At the time, when I was writing the code I was deciding between the pylab approach and the "artist objects" approach that EOL and JKS are refering to, and the "ax" variables were just a left-over from that.
I already knew that, but forgot. With SO and your answer, life became much simpler to me, today. Thanks!
7

For a more general answer to this question and to questions you may soon have, I would recommend the official tutorial.

Comments

0

The best way to show multiple figures is use matplotlib or pylab. (for windows) with matplotlib you can prepare the figures and then when you finish the process with them you can show with the comand "matplotlib.show()" and all figures should be shown.

(on linux) you don´t have problems adding changes to figures because the interactive mode is enable (on windows the interactive mode don't work OK).

1 Comment

I am not sure you are answering the question here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.