dunovank / jupyter-themes

Custom Jupyter Notebook Themes
MIT License
9.76k stars 1.06k forks source link

jtplot support for plotly #332

Open ebauch opened 5 years ago

ebauch commented 5 years ago

Plotly is becoming increasingly relevant for interactive web-type plots, but also supports offline plotting in notebooks. Unfortunately, their dark-theme doesn't play nicely with the jupyterhub dark themes. Maybe we can also support plotly in the near future besides just matplotlib? Here is an example of a dark-theme plotly plot together with onedork theme (note the line template = 'plotly_dark+presentation'):

!jt -t onedork # set onedork theme

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objs as go
import cufflinks as cf
init_notebook_mode(connected=True)

import numpy as np

data1 = go.Scatter(
    name = 'Data 1',
    x = np.random.random(20),
    y = np.random.random(20),
    mode = 'markers',
    marker = dict(
        size = np.random.randint(20, 40, size = 100),
        colorscale='Viridis',
        showscale=False
    )
);

data2 = go.Scatter(
    name = 'Data 2',
    x = np.random.random(20),
    y = np.random.random(20),
    mode = 'markers',
    marker = dict(
        size = np.random.randint(20, 40, size = 100),
        colorscale='Viridis',
        showscale=False
    )
);

layout = go.Layout(
    dict(autosize = False, 
         width = 700,
         height = 550, 
         template = 'plotly_dark+presentation'),
    xaxis = dict(title = 'x axis'),
    yaxis = dict(title = 'y axis'),
    legend = dict(x=0.05, y=0.99),

)

fig = go.Figure(data=[data1, data2], layout=layout)

iplot(fig);

image

I suppose we would have to create a custom plotly template as described here that works well with the juptyer themes.