简体   繁体   中英

Matplotlib and Google Colab: Using ipympl

Whenever I try to plot a figure in a Google Colab notebook using matplotlib, a plot is displayed whenever I use %matplotlib inline but is not displayed when I do %matplotlib ipympl or %matplotlib widget . How can I resolve this issue. My goal is to get the plot to be interactive.

Clarification: when I run %matplotlib --list I get the following output

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

Thanks for your help!

Facing the same issue, I could not get ipympl to work with Colab. However, since you mentioned that " My goal is to get the plot to be interactive ", the next best solution is to use Plotly.

Please see this shared Colab notebook for a minimum example.

Python code also copied below for quick reference:

!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()

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM