def jitter(field_name, width, mean=0, distribution="uniform", range=None): ''' Create a ``DataSpec`` dict to apply a client-side ``Jitter`` transformation to a ``ColumnDataSource`` column. Args: field_name (str) : a field name to configure ``DataSpec`` with width (float) : the width of the random distribition to apply mean (float, optional) : an offset to apply (default: 0) distribution (str, optional) : ``"uniform"`` or ``"normal"`` (default: ``"uniform"``) range (Range, optional) : a range to use for computing synthetic coordinates when necessary, e.g. a ``FactorRange`` when the column data is categorical (default: None) Returns: dict ''' return field( field_name, Jitter(mean=mean, width=width, distribution=distribution, range=range))
import numpy as np from bokeh.io import vplot from bokeh.plotting import figure, show, output_file from bokeh.models.sources import ColumnDataSource from bokeh.models import CustomJS, Button, Label from bokeh.models.transforms import Jitter N = 1000 source = ColumnDataSource(data=dict(x=np.ones(N), xn=2 * np.ones(N), xu=3 * np.ones(N), y=np.random.random(N) * 10)) normal = Jitter(width=0.2, distribution="normal") uniform = Jitter(width=0.2, distribution="uniform") p = figure(x_range=(0, 4), y_range=(0, 10)) p.circle(x='x', y='y', color='firebrick', source=source, size=5, alpha=0.5) p.circle(x='xn', y='y', color='olive', source=source, size=5, alpha=0.5) p.circle(x='xu', y='y', color='navy', source=source, size=5, alpha=0.5) label_data = ColumnDataSource(data=dict( x=[1, 2, 3], y=[10, 10, 10], t=['Original', 'Normal', 'Uniform'])) labels = Label(x='x', y='y', text='t', y_offset=2, source=label_data, render_mode='css',