2

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!

Community
  • 1
  • 1
Anikait Singh
  • 51
  • 1
  • 7
  • Also, I have looked at this thread: https://stackoverflow.com/questions/52859983/interactive-matplotlib-figures-in-google-colab. None of the solutions here worked for me. – Anikait Singh Nov 13 '19 at 20:40
  • Do you have any indication that google colab actually supports this [jupyter-matplotlib](https://github.com/matplotlib/jupyter-matplotlib) backend? I would think that this is not the case, because it is explicitely written with jupyter in mind. – ImportanceOfBeingErnest Nov 13 '19 at 20:46
  • Yes, I clarified above – Anikait Singh Nov 13 '19 at 20:56
  • Oh, that list is not changed by colab. See also https://github.com/matplotlib/matplotlib/issues/15161. I mean you can always ask at colab if they plan to support this anytime soon. – ImportanceOfBeingErnest Nov 13 '19 at 21:02

2 Answers2

1

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()
Marc
  • 2,183
  • 2
  • 11
  • 16
-1

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