Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions examples/misc/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import numpy as np

import matplotlib
matplotlib.use('GtkAgg')
matplotlib.use('TkAgg')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're using canvas API now, this might be portable enough to not require setting a specific backend at all.

import matplotlib.pyplot as plt
import gobject


class ProcessPlotter(object):
Expand All @@ -21,35 +20,33 @@ def __init__(self):
def terminate(self):
plt.close('all')

def poll_draw(self):
def call_back(self):
while 1:
if not self.pipe.poll():
break

def call_back():
while 1:
if not self.pipe.poll():
break
command = self.pipe.recv()

command = self.pipe.recv()
if command is None:
self.terminate()
return False

if command is None:
self.terminate()
return False
else:
self.x.append(command[0])
self.y.append(command[1])
self.ax.plot(self.x, self.y, 'ro')

else:
self.x.append(command[0])
self.y.append(command[1])
self.ax.plot(self.x, self.y, 'ro')

self.fig.canvas.draw()
return True

return call_back
self.fig.canvas.draw()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use draw_idle which defers the actually drawing until the GUI decides to really repaint the screen.

return True

def __call__(self, pipe):
print('starting plotter...')

self.pipe = pipe
self.fig, self.ax = plt.subplots()
self.gid = gobject.timeout_add(1000, self.poll_draw())
timer = self.fig.canvas.new_timer(interval=1000)
timer.add_callback(self.call_back)
timer.start()

print('...done')
plt.show()
Expand Down Expand Up @@ -78,7 +75,7 @@ def main():
for ii in range(10):
pl.plot()
time.sleep(0.5)
raw_input('press Enter...')

pl.plot(finished=True)

if __name__ == '__main__':
Expand Down