brian-team/brian2

[bug] error while plotting spikes with SpikeMonitor

dokato opened this issue · 1 comments

Running an example from the tutorial:

from brian2 import *
start_scope()

N = 100
tau = 10*ms
eqs = '''
dv/dt = (2-v)/tau : 1
'''

G = NeuronGroup(N, eqs, threshold='v>1', reset='v=0', method='exact')
G.v = 'rand()'

spikemon = SpikeMonitor(G)

run(50*ms)

plot(spikemon.t/ms, spikemon.i, '.k')
xlabel('Time (ms)')
ylabel('Neuron index')

I get an error on plotting

    497 if x.shape[0] != y.shape[0]:
    498     raise ValueError(f"x and y must have same first dimension, but "
    499                      f"have shapes {x.shape} and {y.shape}")
--> 500 if x.ndim > 2 or y.ndim > 2:
    501     raise ValueError(f"x and y can be no greater than 2D, but have "
    502                      f"shapes {x.shape} and {y.shape}")
    503 if x.ndim == 1:

AttributeError: 'VariableView' object has no attribute 'ndim'

my brian2 installed from conda on mac m1 is on version 2.5.0.3.

Thanks for the report, this problem seems to have been triggered by changes in matplotlib 3.5.2 (released yesterday), the code runs fine with matplotlib 3.5.1. A simple workaround is to provide a standard numpy array instead of Brian's VariableView to the plot function:

plot(spikemon.t/ms, spikemon.i[:], '.k')