Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Problems with plotly + jupyter notebook

Hi,
I’m using plotly 1.12.9 in Jupyter 4.2.3 on Win 10 64bit, conda 4.2.13, python 3.5.2.
Consider this code:

import plotly as py
import plotly.graph_objs as go

import pandas as pd

py.offline.init_notebook_mode()

# Read data from a csv
z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv')

data = [
    go.Surface(
        z=z_data.as_matrix()
    )
]
layout = go.Layout(
    title='Mt Bruno Elevation',
    autosize=False,
    width=500,
    height=500,
    margin=dict(
        l=65,
        r=50,
        b=65,
        t=90
    )
)
fig = go.Figure(data=data, layout=layout)
py.offline.iplot(fig, filename='elevations-3d-surface')

If I run the code above on Firefox or Chrome, the CPU usage slowly goes up and I have to close the tab to free the CPU. If the code above is executed several times (by recomputing the same cell), the CPU usage goes up much more quickly.

This makes plotly unusable for me.

Hey @gandalf23

Your code and the one below perform fine for me (similar setup except Jupyter 4.3 and Plotly 1.12.11)

for example, following https://plot.ly/python/offline works for me without running slow:

# setup plotly offline
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

print (__version__)

init_notebook_mode(connected=True)

from plotly.graph_objs import *

import pandas as pd


# Read data from a csv
z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv')

data = [
    Surface(
        z=z_data.as_matrix()
    )
]
layout = Layout(
    title='Mt Bruno Elevation',
    autosize=False,
    width=500,
    height=500,
    margin=dict(
        l=65,
        r=50,
        b=65,
        t=90
    )
)
fig = Figure(data=data, layout=layout)
iplot(fig, filename='elevations-3d-surface')

Cheers,
Branden

Hi bcd, thank you for replying!
I even tried to run the code in Chrome with all extensions disabled, but the result is the same.
The code is not running slow, but the cpu usage goes up until one or two cores (out of 8) are completely busy. This happens gradually, but quickly (within 5 minutes). The code keeps running smoothly even then, though.

In the following picture you can see the problem:

If I switch to another tab, the cpu usage goes to 0 (Chrome is smarter than Firefox, it seems) and if I switch back it goes up again. The “GPU process” uses CPU cycles only when I interact with the plot, as it should.

edit: Maybe the problem is that you’re doing a lot of recomputing at each frame even if the plot is completely static. If I lower my monitor’s vfreq from 144 to 60, the problem is less noticeable. CPU time is mostly spent here:

edit2:

edit3:

Anyway, if I use plotly just for 2D I don’t have this issue.