将 alt.Chart() 与来自 google 驱动器 url link 的数据一起使用

Use alt.Chart() with data from a google drive url link

我正在 google colab 中使用 altair 进行绘图。我遇到了 'max row' 警告:https://altair-viz.github.io/user_guide/faq.html#maxrowserror-how-can-i-plot-large-datasets .

这是我的数据集的头部:df.head()

所以现在我正在尝试通过 URL 传递数据,喜欢我的 google 驱动器: 首先我将文件导出到我的驱动器:

"change directory and export whole csv "
os.chdir(Directory.table_dir)
one.to_json('one.json', orient='records')

然后我尝试使用URL数据方法:https://altair-viz.github.io/user_guide/generated/core/altair.UrlData.html#altair.UrlData

os.chdir(Directory.table_dir)
#checking if i can read the file to a pandas dataframe
df=pd.read_json('one.json', orient='records')

source=alt.UrlData('content/gdrive/My Drive/SCTFT/Tables/one.json')


chart = alt.Chart(source).mark_point().encode(
    x='VG:Q',
    y='absID:Q',
    color='file:N',
)
chart

我也试过:

source='content/gdrive/My Drive/SCTFT/Tables/one.json'

使用 df 从 matplotlib 绘图有效。

但是从牵牛星我得到: altair plot

我没有收到任何错误消息。 我应该更改导出文件的方式吗?或者我如何 link 它与 URL?

使用新信息进行编辑

我运行来自https://colab.research.google.com/github/altair-viz/altair_data_server/blob/master/AltairDataServer.ipynb的代码 : pip install first graph

它一直有效,直到:

Altair data server

这只是我在未做任何更改的情况下运行笔记本,所以我的 colab 设置方式一定有问题?

您传递给图表的 URL 数据必须通过 HTTP 请求对前端可见,并且 content/gdrive/My Drive/SCTFT/Tables/one.json 看起来不像是有效的 URL。

由于您的数据位于 Google 驱动器上,无法通过 HTTP URL 获得,我建议 disabling the maximum rows check 并将数据帧直接传递到图表:

alt.data_transformers.enable(max_rows=None)

alt.Chart(df).mark_point().encode(
    x='VG:Q',
    y='absID:Q',
    color='file:N',
)