1

I have been having some trouble with matplotlib since I started using python. When I use the interactive mode, I have to run ipython --pylab --wthread to get plots (if I don't use the --wthread command, it does not plot anything). So far, it hasn't been a problem.

Now, I want to:

  1. Enter a loop
  2. Plot something. This plot is a big plot with two subplots.
  3. AFTER, show a button pannel with easygui to let the user decide depending on what he sees on the plot
  4. close the plot
  5. repeat for each thing to plot in my list.

I am finding several difficulties right now with this:

1) if I try to run the script in an interactive way using the run script.py command, then it does not plot annything, but directly jumps to the button pannel thing. However, if I stop the script, the plots appear. I am pretty sure that what is happening is that the "run" command does not show plots untill the script is done with the for loop. But I need the plots to appear before the buttons.

2) After some tries, I found this code to work (for some mystical reason to me...). I have tried other ways, but removing any of the show() or draw() commands just make the script not to work

fig=plt.figure(figsize=(16,8))

plt.show()

ax1=fig.add_subplot(121)

ax2.things...

ax2=fig.add_subplot(122)

ax2.things

plt.draw()

plt.show()

plt.draw()

showthebuttonsthing...

Even if this is working, matplotlib seems not to get along well with loops, and after 5 seconds of not pressing any button an just waiting, my matplotlib window gets grey. This might sound as something stupid, but colors are important for the decision I want the user the make...

3) I can't find a way to make a python script show plots if I run the python script outside ipython...

I guess there is something really wrong with my matplotlib configuration, but can't find a way to make this work...can anyone give me an hand on this?

Thanks a lot in advance!

Álvaro
  • 1,219
  • 2
  • 12
  • 20

1 Answers1

0

It looks like you've almost got it, but try doing things in this order instead:

fig = plt.figure(figsize=(16,8))
ax = [fig.add_subplot(121),fig.add_subplot(122)]

ax[0].things
ax[1].things

plt.show()

#show the button panel

However, the best method may be to integrate the plot into your GUI. I am not familiar with EasyGUI, but it seems to be based on tk. This example should help you with embedding the figure into a tk window.

Mr. Squig
  • 2,755
  • 17
  • 10
  • I am affraid that did not work, but it could be due to the fact that I am using a function to do the plotting, which is quite complex. However, this is probably a minor thing. What I am most concerned about now is the "grey" thing and the reason why matplotlib seems not to work inside a for loop. I think it has to do with my particular computer (I have seen the same code working in other computer and this does not happen). But so far, I haven't been able to find any answer in the documentation on this problem... But thanks a lot! ;) – Álvaro Oct 14 '12 at 17:14
  • Oh, I didn't see the tk window thing, this is going to be really usefull. Thanks! – Álvaro Oct 14 '12 at 20:31