Skip to main content

CSV Plot Export

Overview

Three plot widgets support exporting their data to CSV files for downstream analysis:

Widget Format Description
Event Plot Long-form tidy One row per event per trial, with relative timestamps
PSTH Plot Long-form tidy One row per histogram bin per event series
Heatmap Plot Wide matrix One row per unit, columns are time-bin values

All CSV files include a metadata comment header (lines starting with #) that records alignment parameters for reproducibility.

How to Export

  1. Open the Properties Panel for the plot widget (visible on the right side when the plot is active).
  2. Scroll to the Export section.
  3. Click Export CSV….
  4. Choose a file path in the save dialog.
  5. A confirmation message appears on success.

The export captures the current state of the plot — including alignment event, window size, scaling mode, and estimation method.

Format Specifications

Event Plot (Raster) CSV

Columns:

Column Type Description
trial_index int Trial number (0-based)
event_key string Name of the event series (e.g., "spikes")
relative_time double Time relative to alignment event (in time units, typically ms)

Example:

# export_type: raster
# alignment_key: stimulus_onset
# window_size: 1000.0
trial_index,event_key,relative_time
0,spikes,-245.3
0,spikes,-102.1
0,spikes,55.7
1,spikes,-312.0
1,spikes,88.4
0,licks,-50.0
0,licks,200.5

PSTH (Histogram) CSV

Columns:

Column Type Description
bin_center double Center of the time bin
event_key string Name of the event series
value double Bin value (count, firing rate, z-score — depends on scaling mode)

Example:

# export_type: psth
# alignment_key: stimulus_onset
# window_size: 1000.0
# scaling_mode: Firing Rate (Hz)
# estimation_method: Binning
bin_center,event_key,value
-495.0,spikes,0.0
-485.0,spikes,2.4
-475.0,spikes,1.8
-495.0,licks,0.0
-485.0,licks,0.5

Heatmap (Aggregate) CSV

Wide-matrix format — one row per unit, columns are bin centers:

# export_type: heatmap_aggregate
# alignment_key: stimulus_onset
# window_size: 1000.0
# scaling_mode: Firing Rate (Hz)
# estimation_method: Binning
unit_key,-495.0,-485.0,-475.0,-465.0
unit_A,0.4,1.2,3.7,2.1
unit_B,0.0,0.3,0.5,0.1
unit_C,1.1,4.5,6.2,3.8

Loading in Python

All formats use # comment lines. Pass comment='#' to pd.read_csv() to skip them automatically.

Raster

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

df = pd.read_csv("event_plot.csv", comment="#")

fig, ax = plt.subplots(figsize=(8, 5))
sns.stripplot(
    data=df, x="relative_time", y="trial_index",
    hue="event_key", jitter=False, orient="h",
    size=2, ax=ax
)
ax.set_xlabel("Time relative to alignment (ms)")
ax.set_ylabel("Trial")
ax.invert_yaxis()
plt.tight_layout()
plt.show()

PSTH

df = pd.read_csv("psth.csv", comment="#")

fig, ax = plt.subplots(figsize=(8, 4))
sns.lineplot(
    data=df, x="bin_center", y="value",
    hue="event_key", ax=ax
)
ax.set_xlabel("Time relative to alignment (ms)")
ax.set_ylabel("Value")
plt.tight_layout()
plt.show()

Heatmap

df = pd.read_csv("heatmap.csv", comment="#", index_col=0)

fig, ax = plt.subplots(figsize=(10, 6))
sns.heatmap(df.astype(float), cmap="inferno", ax=ax)
ax.set_xlabel("Time (ms)")
ax.set_ylabel("Unit")
plt.tight_layout()
plt.show()

Loading in R

Use readr::read_csv(comment='#') to skip metadata lines.

Raster

library(readr)
library(ggplot2)

df <- read_csv("event_plot.csv", comment = "#")

ggplot(df, aes(x = relative_time, y = trial_index, color = event_key)) +
  geom_point(size = 0.8) +
  scale_y_reverse() +
  labs(x = "Time relative to alignment (ms)", y = "Trial") +
  theme_minimal()

PSTH

df <- read_csv("psth.csv", comment = "#")

ggplot(df, aes(x = bin_center, y = value, color = event_key)) +
  geom_line() +
  labs(x = "Time relative to alignment (ms)", y = "Value") +
  theme_minimal()

Heatmap

library(tidyr)

df <- read_csv("heatmap.csv", comment = "#")

# Pivot to long form for ggplot
long_df <- df |>
  pivot_longer(-unit_key, names_to = "bin_center", values_to = "value") |>
  mutate(bin_center = as.numeric(bin_center))

ggplot(long_df, aes(x = bin_center, y = unit_key, fill = value)) +
  geom_tile() +
  scale_fill_viridis_c() +
  labs(x = "Time (ms)", y = "Unit") +
  theme_minimal()

Metadata Comment Header

Every exported CSV starts with comment lines (prefixed with #) that record the parameters used to generate the data:

Field Description Present in
export_type Format identifier (raster, psth, heatmap_aggregate) All
alignment_key DataManager key of the alignment event series All
window_size Time window size (in time units) All
scaling_mode Scaling applied to values (e.g., “Firing Rate (Hz)”, “Z-Score”) PSTH, Heatmap
estimation_method Rate estimation method (e.g., “Binning”, “GaussianKernel”) PSTH, Heatmap

These fields are for documentation and reproducibility only — they do not affect how the data rows are parsed.