<jupyter_start><jupyter_text>Make the plot for one cell<jupyter_code>def cell_response_panel(raster):
    fig, ax = plt.subplots(3, 3, figsize=(9, 9), gridspec_kw=dict(hspace=0.2))
    sessions = ["exp022", "blanks", "lag"]
    t = None
    y_lab_loc = 0
    for j, t_range in enumerate([(10, 10, 0.5), (2, 2, 0.1)]):
        for i, s in enumerate(sessions):
            if raster[s] is not None:
                # spikes, pre_int_sec, post_int_sec, step, ax=None, events=None
                single_plot(
                    raster[s]["spk"],
                    t_range[0],
                    t_range[1],
                    t_range[2],
                    ax=ax[i][j],
                    events=raster[s]["twc"],
                )
                t = raster[s]["name"]
                y_lab_loc = i
            else:
                ax[i][j].set_visible(False)

    for i, s in enumerate(["exp022", "blanks", "lag"]):
        if raster[s] is not None:
            single_plot(
                raster[s]["spk_twc"],
                0.15,
                0.15,
                0.01,
                ax=ax[i][2],
                events=raster[s]["twc_twc"],
            )
        else:
            ax[i][2].set_visible(False)

    xlabels = ["Time from bout (s)"] * 2 + ["Time from twitch (s)"]
    for ax_i in range(3):
        ax[ax_i][0].set_ylabel("{}\n(Spikes/s)".format(sessions[ax_i]), labelpad=30)
        for ax_j in range(3):
            if ax_i != y_lab_loc:
                ax[ax_i][ax_j].set_xticklabels([])
            else:
                ax[ax_i][ax_j].set_xlabel(xlabels[ax_j])
    plt.suptitle(t)
    plt.legend()
    sns.despine()
    # plt.tight_layout()
cell_response_panel(raster_collection[28])<jupyter_output><empty_output><jupyter_text>Dirtylegend<jupyter_code>f = plt.figure(figsize=(3, 3))
plt.plot(1, color=sns.color_palette()[0], alpha=0.4, label="tail")
plt.plot(1, color=sns.color_palette()[2], label="spikes")
plt.axhspan(0, 0, color="k", alpha=0.1, zorder=-500, label="99% conf.")
plt.legend()
sns.despine()
f.savefig("/Users/luigipetrucco/Desktop/legend.pdf")<jupyter_output><empty_output><jupyter_text>Export pdf with all cells<jupyter_code>from matplotlib.backends.backend_pdf import PdfPages
with PdfPages("/Users/luigipetrucco/Desktop/all_cells_motor_resp.pdf") as pdf:
    for raster in raster_collection:
        cell_response_panel(raster)
        pdf.savefig()  # saves the current figure into a pdf page
        plt.close()<jupyter_output><empty_output><jupyter_text>Colorplot with all cells:<jupyter_code>pre_int_sec = 10
post_int_sec = 10
CONF_INT_COEF = 1.96

pooled_spk = [
    raster["exp022"]["spk"]
    for raster in raster_collection
    if raster["exp022"] is not None
]
pooled_bouts = [
    raster["exp022"]["twc"]
    for raster in raster_collection
    if raster["exp022"] is not None
]
pre_int_sec = 10
post_int_sec = 10
step = 0.5
hst_arr = np.arange(-pre_int_sec, post_int_sec, step)
histograms_10s = np.array(
    [nanzscore(np.histogram(p[:, 0].flatten() / fn, hst_arr)[0]) for p in pooled_spk]
)
histograms_10s_twc = np.array(
    [nanzscore(np.histogram(p[:, 0].flatten() / fn, hst_arr)[0]) for p in pooled_bouts]
)
# histograms_10s[np.abs(histograms_10s) < CONF_INT_COEF] = 0


pre_int_sec = 2
post_int_sec = 2
step = 0.1
hst_arr = np.arange(-pre_int_sec, post_int_sec, step)
histograms_2s = np.array(
    [nanzscore(np.histogram(p[:, 0].flatten() / fn, hst_arr)[0]) for p in pooled_spk]
)
histograms_2s_twc = np.array(
    [nanzscore(np.histogram(p[:, 0].flatten() / fn, hst_arr)[0]) for p in pooled_bouts]
)
# histograms_2s[np.abs(histograms_2s) < CONF_INT_COEF] = 0
f = plt.figure()
i_sort = 20

ax10_im = f.add_axes((0.1, 0.3, 0.35, 0.4))
# plt.subplot(1,2,1)
ax10_im.imshow(
    histograms_10s[np.argsort(histograms_10s[:, i_sort]), :],
    cmap="RdBu_r",
    vmin=-3,
    vmax=3,
    aspect="auto",
)
# ax10_im.set_yticks([])
ax10_im.set_xticks(np.arange(0, histograms_10s.shape[1], 10))
ax10_im.set_xticklabels(np.arange(0, histograms_10s.shape[1] + 5, 10) / 2 - 10)
ax10_im.set_ylabel("Cell (sorted on motor resp.)")
ax10_im.set_xlabel("Time from bout (s)")

ax10_bt = f.add_axes((0.1, 0.71, 0.35, 0.15))
ax10_bt.step(
    np.arange(histograms_10s_twc.shape[1]), np.mean(histograms_10s_twc, 0), alpha=0.4
)
ax10_bt.set_xlim(0, histograms_2s_twc.shape[1])
ax10_bt.axis("off")

ax2_im = f.add_axes((0.5, 0.3, 0.35, 0.4))
# plt.subplot(1,2,1)
ax2_im.imshow(
    histograms_2s[np.argsort(histograms_2s[:, i_sort]), :],
    cmap="RdBu_r",
    vmin=-3,
    vmax=3,
    aspect="auto",
)
ax2_im.set_yticks([])
ax2_im.set_xticks(np.arange(0, histograms_2s.shape[1], 10))
ax2_im.set_xticklabels(np.arange(0, histograms_2s.shape[1] + 5, 10) / 10 - 2)

ax2_bt = f.add_axes((0.5, 0.71, 0.35, 0.15))
ax2_bt.step(
    np.arange(histograms_2s_twc.shape[1]), np.mean(histograms_2s_twc, 0), alpha=0.4
)
ax2_bt.set_xlim(0, histograms_2s_twc.shape[1])
ax2_bt.axis("off")
ax2_im.set_xlabel("Time from bout (s)")
sns.despine(left=True, top=True, bottom=True)
f.savefig("/Users/luigipetrucco/Desktop/summary_ephys.pdf")
def cell_response_panel(raster):
    fig, ax = plt.subplots(3, 3, figsize=(9, 9), gridspec_kw=dict(hspace=0.2))
    sessions = ["exp022", "blanks", "lag"]
    t = None
    y_lab_loc = 0
    for j, t_range in enumerate([(10, 10, 0.5), (2, 2, 0.1)]):
        for i, s in enumerate(sessions):
            if raster[s] is not None:
                # spikes, pre_int_sec, post_int_sec, step, ax=None, events=None
                single_plot(
                    raster[s]["spk"],
                    t_range[0],
                    t_range[1],
                    t_range[2],
                    ax=ax[i][j],
                    events=raster[s]["twc"],
                )
                t = raster[s]["name"]
                y_lab_loc = i
            else:
                ax[i][j].set_visible(False)

    for i, s in enumerate(["exp022", "blanks", "lag"]):
        if raster[s] is not None:
            single_plot(
                raster[s]["spk_twc"],
                0.15,
                0.15,
                0.01,
                ax=ax[i][2],
                events=raster[s]["twc_twc"],
            )
        else:
            ax[i][2].set_visible(False)

    xlabels = ["Time from bout (s)"] * 2 + ["Time from twitch (s)"]
    for ax_i in range(3):
        ax[ax_i][0].set_ylabel("{}\n(Spikes/s)".format(sessions[ax_i]), labelpad=30)
        for ax_j in range(3):
            if ax_i != y_lab_loc:
                ax[ax_i][ax_j].set_xticklabels([])
            else:
                ax[ax_i][ax_j].set_xlabel(xlabels[ax_j])
    plt.suptitle(t)
    sns.despine()
    # plt.tight_layout()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15944411237298267, 'fraction_numerical': 0.04423191870890616, 'mean_word_length': 2.6022604951560817, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '653034', 'license': 'MIT', 'n_tokens_mistral': 2910, 'n_tokens_neox': 2687, 'n_words': 453, 'path': 'notebooks/ephys/plottone_della_morte.ipynb', 'repo_name': 'portugueslab/ec-code', 'size': '6692'}