Plotting of arbitrary functions

Hi. I agree that this is something that we should support in a more convenient way… Here’s what I usually do: I set the function argument (often the membrane potential v) to the full range of values in a NeuronGroup, and then directly plot the variable that is described by an equation. This has the advantage of not having to change the equations and is also not actually running a simulation (the expression gets directly evaluated by numpy). It is still not a perfect solution, since you usually have to create a NeuronGroup just for this purpose (if the existing NeuronGroup does not happen to have exactly the size you want for the resolution). In your example, x would probably be a differential equation, so it would look something like this:

import matplotlib.pyplot as plt
import numpy as np
from brian2 import NeuronGroup

group = NeuronGroup(100,  # the resolution I want
                    """dx/dt = -x / (10*ms) : 1  # this would be v typically
                       y = x**2 : 1  # the function I'm interested in""",
                    method='euler')
group.x = np.linspace(-100, 100, len(group))

plt.plot(group.x, group.y)
plt.xlabel('x')
plt.ylabel('x*x')
plt.savefig("brian_plotting.png")

This will give you the same plot.

2 Likes