A JupyterLab extension for rendering Plotly charts
- JupyterLab ^0.30.0
- plotly.py >= 2.0.0
To render Plotly JSON in IPython:
from IPython.display import display
def Plotly(data=[], layout={}):
bundle = {}
bundle['application/vnd.plotly.v1+json'] = {
'data': data,
'layout': layout,
}
display(bundle, raw=True)
data = [
{'x': [1999, 2000, 2001, 2002], 'y': [10, 15, 13, 17], 'type': 'scatter'},
{'x': [1999, 2000, 2001, 2002], 'y': [16, 5, 11, 9], 'type': 'scatter'}
]
layout = {
'title': 'Sales Growth',
'xaxis': {'title': 'Year', 'showgrid': False, 'zeroline': False},
'yaxis': {'title': 'Percent', 'showline': False}
}
Plotly(data, layout)To render using the plotly Python library:
from plotly.offline import iplot
trace = plotly.graph_objs.Heatmap(z=[[1, 20, 30],
[20, 1, 60],
[30, 60, 1]])
fig = dict(data=[trace])
iplot(fig)To render a .plotly or .plotly.json file, simply open it:
jupyter labextension install @jupyterlab/plotly-extension# Clone the repo to your local environment
git clone https://github.com/jupyterlab/jupyter-renderers.git
cd jupyter-renderers
# Install dependencies
yarn install
# Build Typescript source
yarn run build
# Link your development version of the extension with JupyterLab
jupyter labextension link packages/plotly-extension
# Rebuild Typescript source after making changes
yarn run build
# Rebuild JupyterLab after making any changes
jupyter lab buildYou can watch the jupyter-renderers directory and run JupyterLab in watch mode to watch for changes in the extension's source and automatically rebuild the extension and application.
# Run jupyterlab in watch mode in one terminal tab
jupyter lab --watch
# Watch the jupyter-renderers directory
yarn run watchjupyter labextension uninstall @jupyterlab/plotly-extension