" 'marker': {'opacity': 0}}], # invisible trace to init axes and to support autoresize\n",
...
...
@@ -174,7 +181,7 @@
"outputs": [],
"source": [
"# Set background image\n",
"f.layout.images = [dict(\n",
"f.layout.images = [go.layout.Image(\n",
" source = initial_img, # plotly now performs auto conversion of PIL image to png data URI\n",
" xref = \"x\",\n",
" yref = \"y\",\n",
...
...
%% Cell type:markdown id: tags:
# Overview
This notebook demonstrates how to use DataShader to display large datasets inside a plotly `FigureWidget`. Change callbacks are used to recompute the datashader image whenever the axis range or figure size changes
%% Cell type:markdown id: tags:
## Imports
%% Cell type:code id: tags:
``` python
from plotly.graph_objs import FigureWidget
# core
import io
import base64
import time
# pandas
import pandas as pd
# numpy
import numpy as np
# scikit learn
from sklearn import datasets
# datashader
import datashader as ds
import datashader.transfer_functions as tf
from datashader.colors import inferno
```
%% Cell type:markdown id: tags:
## Generate dataset
We will create a large dataset by duplicating the Iris dataset many times with random noise
%% Cell type:code id: tags:
``` python
num_copies = 7000 # 1,050,000 rows
iris_data = datasets.load_iris()
feature_names = [name.replace(' (cm)', '').replace(' ', '_') for name in iris_data.feature_names]
Define a function that inputs an x/y ranges and the plot width/height and generates a DataShader image of the dataset. The image will be returned as a PIL image object