Data transformations allow you to specify a way to transform data instead of doing the transform yourself. This means that you can send your raw data to the client and the transformation will happen client side. This can be efficient becuase:
In bokeh there are Transforms and ColorMappers that fall into this category:
from bokeh.sampledata.autompg import autompg
autompg.head()
mpg | cyl | displ | hp | weight | accel | yr | origin | name | |
---|---|---|---|---|---|---|---|---|---|
0 | 18.0 | 8 | 307.0 | 130 | 3504 | 12.0 | 70 | 1 | chevrolet chevelle malibu |
1 | 15.0 | 8 | 350.0 | 165 | 3693 | 11.5 | 70 | 1 | buick skylark 320 |
2 | 18.0 | 8 | 318.0 | 150 | 3436 | 11.0 | 70 | 1 | plymouth satellite |
3 | 16.0 | 8 | 304.0 | 150 | 3433 | 12.0 | 70 | 1 | amc rebel sst |
4 | 17.0 | 8 | 302.0 | 140 | 3449 | 10.5 | 70 | 1 | ford torino |
from bokeh.models import ColumnDataSource
source = ColumnDataSource(autompg)
source.column_names
['hp', 'index', 'origin', 'yr', 'name', 'displ', 'accel', 'mpg', 'weight', 'cyl']
from bokeh.plotting import figure
p = figure(height=400, x_axis_label='year', y_axis_label='mpg')
p.circle(x='yr', y='mpg', alpha=0.6, size=15, source=source)
show(p)
We use the explicit field specification to spell the data transform
from bokeh.models import Jitter
p = figure(height=400, width=800, x_axis_label='year', y_axis_label='mpg')
p.circle(x={'field': 'yr', 'transform': Jitter(width=0.2)}, y=autompg.mpg, alpha=0.6, size=15, source=source)
show(p)
from bokeh.models import LinearInterpolator
size_mapper = LinearInterpolator(
x=[autompg.hp.min(), autompg.hp.max()],
y=[3, 30]
)
p = figure(height=400, width=800, x_axis_label='year', y_axis_label='mpg')
p.circle(x='yr', y=autompg.mpg, alpha=0.6, size={'field': 'hp', 'transform': size_mapper}, source=source)
show(p)
from bokeh.models import LinearColorMapper
from bokeh.palettes import Viridis256
color_mapper = LinearColorMapper