【问题标题】:Matplotlib and Google Colab: Using ipymplMatplotlib 和 Google Colab:使用 ipympl
【发布时间】:2020-03-09 17:35:26
【问题描述】:

每当我尝试使用 matplotlib 在 Google Colab 笔记本中绘制图形时,每当我使用 %matplotlib inline 时都会显示一个绘图,但在我使用 %matplotlib ipympl%matplotlib widget 时不会显示。我该如何解决这个问题。我的目标是让情节具有互动性。

澄清:当我运行%matplotlib --list 时,我得到以下输出

Available matplotlib backends: ['tk', 'gtk', 'gtk3', 'wx', 'qt4', 'qt5', 'qt', 'osx', 'nbagg', 'notebook', 'agg', 'inline', 'ipympl', 'widget']

感谢您的帮助!

【问题讨论】:

标签: python matplotlib google-colaboratory


【解决方案1】:

面对同样的问题,我无法让 ipympl 与 Colab 合作。但是,由于您提到“我的目标是让情节具有交互性”,因此下一个最佳解决方案是使用 Plotly。

请参阅此shared Colab notebook 了解最小示例。

以下也复制了 Python 代码以供快速参考:

!pip install plotly

import plotly.express as px

SHEET_ID = '153pKW5IZRHwx9mLu_uU-hDSK0D3R19vR71EcgMYHn3I'

df = pd.read_csv('https://docs.google.com/spreadsheets/d/' + SHEET_ID + '/export?format=csv')

fig = px.scatter(data_frame=df, x="x", y="y", width=1000, height=800)
fig.show()

【讨论】:

    【解决方案2】:

    可用的 matplotlib 后端:['tk', 'gtk', 'gtk3', 'wx', 'qt4', 'qt5', 'qt', 'osx', 'nbagg', 'notebook', 'agg ', '内联', 'ipympl', 'widget']

    【讨论】:

    • 请添加更多信息和来源
    猜你喜欢
    • 2022-11-13
    • 2019-03-22
    • 2020-11-16
    • 1970-01-01
    • 2020-07-21
    • 2020-07-24
    • 2021-11-10
    • 1970-01-01
    • 2020-06-20
    相关资源
    最近更新 更多