1

I have a programme which creates an interactive matplotlib (well, pylab) figure, then waits for a raw_input while letting the user manipulate the plot to manually find the best data.

import pylab as p
p.ion()
p.figure(1)
p.plot(x,y,'.')
cen=float(raw_input('Type centre:'))
dur=float(raw_input('Type duration:'))
depth=float(raw_input('Type depth:'))

If I run this on linux (matplotlib 1.4.3), it works as expected. Running this on my Mac (matplotlib 1.5.0) freezes the pylab window at it's first draw and doesn't let the interactive features work. After something is entered into the raw_input, however, it draws all the preceding interactive clicks. Any ideas?

HPOsborn
  • 11
  • 2
  • add ```plt.pause(0.0001)``` see this thread: http://stackoverflow.com/questions/12670101/matplotlib-ion-function-fails-to-be-interactive – Bernuly Mar 05 '17 at 04:29

1 Answers1

2

ion() and raw_input() do not work well together. This is a known problem. In interactive mode pyplot.ion() is using an event handler to wait for keypresses. This breaks when raw_input takes over the input.

You can make it a bit better by adding draw() or show():

import pylab as p
p.ion()
p.figure(1)
p.plot(x,y,'.')
p.show()
cen=float(raw_input('Type centre:'))
dur=float(raw_input('Type duration:'))
depth=float(raw_input('Type depth:')) 
tuomastik
  • 4,559
  • 5
  • 36
  • 48
Tom Kooij
  • 21
  • 4