From eaa1d56f1cc6ac0c5a4737fde099b606b48edcc0 Mon Sep 17 00:00:00 2001 From: Simon Brodeur Date: Sat, 11 May 2013 11:15:23 -0400 Subject: [PATCH 1/2] Bug fix to allow multiple realtime raster plots. The previous usage of pylab.gca() during the refresh operation caused only the foreground figure to be updated. One may validate the proper behavior now with this example script: ################################################# from brian import * import pylab if __name__ == '__main__': pylab.ion() eqs = ''' dv/dt = (ge+gi-(v+49*mV))/(20*ms) : volt dge/dt = -ge/(5*ms) : volt dgi/dt = -gi/(10*ms) : volt ''' P = NeuronGroup(300, eqs, threshold=-50*mV, reset=-60*mV) P.v = -60*mV Pe = P.subgroup(200) Pi = P.subgroup(100) Ce = Connection(Pe, P, 'ge', weight=1.62*mV, sparseness=0.02) Ci = Connection(Pi, P, 'gi', weight=-9*mV, sparseness=0.02) M1 = SpikeMonitor(Pe) M2 = SpikeMonitor(Pi) raster_plot(M1, newfigure=True, refresh=500*ms, showlast=1000*ms, redraw=True) raster_plot(M2, newfigure=True, refresh=100*ms, showlast=1000*ms, redraw=True) run(10*second) pylab.ioff() --- brian/plotting.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/brian/plotting.py b/brian/plotting.py index b6c27b5f..fdc578eb 100644 --- a/brian/plotting.py +++ b/brian/plotting.py @@ -186,25 +186,30 @@ def get_plot_coords(tmin=None, tmax=None): return st, sn, nmax st, sn, nmax = get_plot_coords() if myopts['newfigure']: - pylab.figure() + fig = pylab.figure() + ax = fig.add_subplot(1, 1, 1) + else: + fig = pylab.gcf() + ax = fig.gca() + if myopts['refresh'] is None: - line, = pylab.plot(st, sn, '.', **plotoptions) + line, = ax.plot(st, sn, '.', **plotoptions) else: - line, = pylab.plot([], [], '.', **plotoptions) + line, = ax.plot([], [], '.', **plotoptions) if myopts['refresh'] is not None: - pylab.axis(ymin=0, ymax=nmax) + ax.set_ylim(0, nmax) if myopts['showlast'] is not None: - pylab.axis(xmin= -myopts['showlast'] / ms, xmax=0) - ax = pylab.gca() + ax.set_xlim(-myopts['showlast'] / ms, 0) + if myopts['showgrouplines']: for i in range(len(monitors)): - pylab.axhline(i, color=myopts['grouplinecol']) - pylab.axhline(i + (1 - spacebetween), color=myopts['grouplinecol']) - pylab.ylabel(myopts['ylabel']) - pylab.xlabel(myopts['xlabel']) - pylab.title(myopts["title"]) + ax.axhline(i, color=myopts['grouplinecol']) + ax.axhline(i + (1 - spacebetween), color=myopts['grouplinecol']) + ax.set_ylabel(myopts['ylabel']) + ax.set_xlabel(myopts['xlabel']) + ax.set_title(myopts["title"]) if myopts["showplot"]: - pylab.show() + fig.show() if myopts['refresh'] is not None: @network_operation(clock=EventClock(dt=myopts['refresh'])) def refresh_raster_plot(clk): @@ -220,8 +225,8 @@ def refresh_raster_plot(clk): line.set_xdata(array(st)) line.set_ydata(sn) if myopts['redraw']: - pylab.draw() - pylab.get_current_fig_manager().canvas.flush_events() + fig.canvas.draw() + fig.canvas.flush_events() monitors[0].contained_objects.append(refresh_raster_plot) From 09a5fe43382158eb6d750204340a4be60a1da167 Mon Sep 17 00:00:00 2001 From: Simon Brodeur Date: Sat, 11 May 2013 11:37:04 -0400 Subject: [PATCH 2/2] Use pylab.show() to freeze the figure --- brian/plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brian/plotting.py b/brian/plotting.py index fdc578eb..3d5127c1 100644 --- a/brian/plotting.py +++ b/brian/plotting.py @@ -209,7 +209,7 @@ def get_plot_coords(tmin=None, tmax=None): ax.set_xlabel(myopts['xlabel']) ax.set_title(myopts["title"]) if myopts["showplot"]: - fig.show() + pylab.show() if myopts['refresh'] is not None: @network_operation(clock=EventClock(dt=myopts['refresh'])) def refresh_raster_plot(clk):