Skip to content

Instantly share code, notes, and snippets.

@Seanny123
Created June 13, 2016 22:25
Show Gist options
  • Save Seanny123/42ae53a075f3a4ab1f1f946451eb27ee to your computer and use it in GitHub Desktop.
Save Seanny123/42ae53a075f3a4ab1f1f946451eb27ee to your computer and use it in GitHub Desktop.
Bar plot example
import nengo
import numpy as np
fsp_res = 4
with nengo.Network() as model:
def in_func(t, x):
idx = int((t * 100) % fsp_res)
val = np.ones(fsp_res)
val[idx:idx+1] = 0.5
return val*x
in_nd = nengo.Node(in_func, size_in=1)
mult = nengo.Node([1])
nengo.Connection(mult, in_nd)
bar_x = np.linspace(0, 50, fsp_res)
def out_func(t, x):
line_width = 2
bar_graph = '''<svg width="100%" height="100%" viewbox="0 0 200 100">'''
for ii in range(fsp_res):
bar_graph += '''<line x1="{0}" y1="0" x2="{0}" y2="{1}" stroke-width="{2}" style="stroke:black"/>'''.format(
bar_x[ii] * line_width, x[ii]*100, line_width)
out_func._nengo_html_ = bar_graph
out_nd = nengo.Node(out_func, size_in=fsp_res)
val_nd = nengo.Node(size_in=fsp_res)
nengo.Connection(in_nd, out_nd, synapse=None)
nengo.Connection(in_nd, val_nd, synapse=None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment