0

I have some python simulation code that runs for a minute or two and displays the output of the simulation in real-time.

I would like to show results on two different figure windows. Because I'm using an object oriented design, it's a little difficult to switch between the figures using the figure(x) command, so I want to save a reference to each figure to each variable and use that to return to them. I've set it up like the following:

import pylab as p 

f0 = p.figure() 
f1 = p.figure() 
ax0 = f0.add_subplot(111) 
ax0.plot(range(0,50))
ax1 = f1.add_subplot(111) 
ax1.plot(range(0,20))
ax1.text(0,1,"This is updatable",weight='bold',fontsize=16)
ax0.text(0,1,"This one, drawn first, is not.",weight='bold',fontsize=16)
p.pause(5)

The problem is that once I've created and accessed the second figure, the first figure is no longer accessible.

I am using matplotlib and running Python 2.7.6 using Pycharm CE with the MacOSX interactive backend.

Does anyone know how to set this up? Am I using the wrong graphing package for this kind of problem?

UPDATE: I found that if I closed the first window just using my mouse to access the on-window controls, then the second window would be updated. That doesn't solve my problem, though.

Ben Smith
  • 85
  • 2
  • 11
  • Try adding 'p.show()' at the end – CE ZHANG Oct 12 '15 at 07:47
  • No luck @problemMaker, although I found that regardless of whether p.show() was added, if I closed the first window just using my mouse to access the on-window controls, then the second window would be updated. – Ben Smith Oct 12 '15 at 18:43

1 Answers1

0

This is a bit workaround-y but I found one solution is to make whichever figure I want updated to be the current figure, using the command:

p.figure(f0.number)

I wasn't aware I could access the number of the figure like this, but this does seem to get around my problem!

Community
  • 1
  • 1
Ben Smith
  • 85
  • 2
  • 11