Skip to content
Snippets Groups Projects
Unverified Commit f7a6fc8c authored by Brent Huisman's avatar Brent Huisman Committed by GitHub
Browse files

Update Python examples to work with latest Pandas+Seaborn (#1625)

Latest Pandas versions required unique indices, breaking the plotting in the python examples.
parent 0998de7b
No related branches found
No related tags found
No related merge requests found
......@@ -137,5 +137,5 @@ for gid in range(ncells):
samples, meta = sim.samples(handles[gid])[0]
df_list.append(pandas.DataFrame({'t/ms': samples[:, 0], 'U/mV': samples[:, 1], 'Cell': f"cell {gid}"}))
df = pandas.concat(df_list)
df = pandas.concat(df_list,ignore_index=True)
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Cell",ci=None).savefig('network_ring_result.svg')
......@@ -143,5 +143,5 @@ for gid in range(ncells):
df_list.append(pandas.DataFrame({'t/ms': samples[:, 0], 'U/mV': samples[:, 1], 'Cell': f"cell {gid}"}))
if len(df_list):
df = pandas.concat(df_list)
df = pandas.concat(df_list,ignore_index=True)
df.to_csv(f"result_mpi_{context.rank}.csv", float_format='%g')
......@@ -10,5 +10,5 @@ df_list = []
for result in results:
df_list.append(pandas.read_csv(result))
df = pandas.concat(df_list)
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Cell",ci=None).savefig('mpi_result.svg')
\ No newline at end of file
df = pandas.concat(df_list,ignore_index=True)
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Cell",ci=None).savefig('mpi_result.svg')
......@@ -118,8 +118,8 @@ for s in model.spikes:
# (10) Plot the voltages
df = pandas.DataFrame()
df_list = []
for t in model.traces:
df=df.append(pandas.DataFrame({'t/ms': t.time, 'U/mV': t.value, 'Location': str(t.location), 'Variable': t.variable}))
df_list.append(pandas.DataFrame({'t/ms': t.time, 'U/mV': t.value, 'Location': str(t.location), 'Variable': t.variable}))
df = pandas.concat(df_list,ignore_index=True)
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Location",col="Variable",ci=None).savefig('single_cell_detailed_result.svg')
......@@ -182,7 +182,8 @@ for d, m in sim.samples(handle):
data.append(d)
meta.append(m)
df = pandas.DataFrame()
df_list = []
for i in range(len(data)):
df = df.append(pandas.DataFrame({'t/ms': data[i][:, 0], 'U/mV': data[i][:, 1], 'Location': str(meta[i]), 'Variable':'voltage'}))
df_list.append(pandas.DataFrame({'t/ms': data[i][:, 0], 'U/mV': data[i][:, 1], 'Location': str(meta[i]), 'Variable':'voltage'}))
df = pandas.concat(df_list,ignore_index=True)
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Location",col="Variable",ci=None).savefig('single_cell_recipe_result.svg')
......@@ -4,8 +4,6 @@
import arbor
import pandas, seaborn # You may have to pip install these.
print(arbor.__config__)
# (1) Create a morphology with a single (cylindrical) segment of length=diameter=6 μm
tree = arbor.segment_tree()
tree.append(arbor.mnpos, arbor.mpoint(-3, 0, 0, 3), arbor.mpoint(3, 0, 0, 3), tag=1)
......@@ -41,11 +39,11 @@ if len(m.spikes)>0:
else:
print('no spikes')
# (8) Plot the recorded voltages over time.
# (9) Plot the recorded voltages over time.
print("Plotting results ...")
seaborn.set_theme() # Apply some styling to the plot
df = pandas.DataFrame({'t/ms': m.traces[0].time, 'U/mV': m.traces[0].value})
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",ci=None).savefig('single_cell_model_result.svg')
# (9) Optionally, you can store your results for later processing.
# (10) Optionally, you can store your results for later processing.
df.to_csv('single_cell_model_result.csv', float_format='%g')
......@@ -103,6 +103,6 @@ df_list = []
for t in m.traces:
df_list.append(pandas.DataFrame({'t/ms': t.time, 'U/mV': t.value, 'Location': str(t.location), "Variable": t.variable}))
df = pandas.concat(df_list)
df = pandas.concat(df_list,ignore_index=True)
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Location",col="Variable",ci=None).savefig('single_cell_nml.svg')
......@@ -87,7 +87,7 @@ else:
print('no spikes')
print("Plotting results ...")
seaborn.set_theme() # Apply some styling to the plot
df = pandas.DataFrame({'t/ms': data[:, 0], 'U/mV': data[:, 1]})
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV", ci=None).savefig('single_cell_recipe_result.svg')
......
......@@ -95,6 +95,6 @@ df_list = []
for t in m.traces:
df_list.append(pandas.DataFrame({'t/ms': t.time, 'U/mV': t.value, 'Location': str(t.location), "Variable": t.variable}))
df = pandas.concat(df_list)
df = pandas.concat(df_list,ignore_index=True)
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Location",col="Variable",ci=None).savefig('single_cell_swc.svg')
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment