在 google colab 中使用 mne 包生成交互式绘图

Generate interactive plot using mne package in google colab

我正在尝试使用 mne 包生成 EEG 数据的交互图。但它不适用于 Google Colab。相反,它给了我 2 个完全相同的静态图。知道如何解决吗?

解决方案

据我所知,Google Colab 目前不允许使用 %matplotlib notebook 作为后端。通常,人们在制作 matplotlib 图时使用 %matplotlib notebook 进行交互。您使用的包似乎使用 matplotlib 进行可视化。所以,现在,你运气不好!

您将使用其他库:altair, plotly, bokeh 等在 Colab 上实现交互。

查看此 colab 笔记本:Charting in Colaboratory。 colab-notebook.

中有各种可视化包的详细示例,可帮助您入门

Colab 上交互式绘图的示例 Altair 代码

Altair is a declarative visualization library for creating interactive visualizations in Python, and is installed and enabled in Colab by default.

例如,这是一个交互式散点图:

import altair as alt
from vega_datasets import data
cars = data.cars()

alt.Chart(cars).mark_point().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
).interactive()

参考资料

我建议您也看看以下资源。

  1. Charting in Colaboratory - colab-notebook-example