This docs on this page refers to a PREVIOUS VERSION. For the latest stable release, go to https://docs.bokeh.org/

Archived docs for versions <= 1.0.4 have had to be modified from their original published configuration, and may be missing some features (e.g. source listing)

All users are encourage to update to version 1.1 or later, as soon as they are able.

jitter.py — Bokeh 0.12.5 documentation

jitter.py

Pan
Box Zoom
Wheel Zoom
Save
Reset
Click the question mark to learn more about Bokeh plot tools.
Pan
Box Zoom
Wheel Zoom
Save
Reset
Click the question mark to learn more about Bokeh plot tools.

from bokeh.models import Jitter
from bokeh.layouts import column
from bokeh.plotting import figure, show, output_file
from bokeh.sampledata.autompg import autompg as df


colors = ["red", "olive", "darkred", "goldenrod", "skyblue", "orange", "salmon"]

p1 = figure(plot_width=600, plot_height=300, title="Years vs mpg without jittering")
p2 = figure(plot_width=600, plot_height=300, title="Years vs mpg with jittering")

for i, year in enumerate(list(df.yr.unique())):
    y = df[df['yr'] == year]['mpg']
    color = colors[i % len(colors)]

    p1.circle(x=year, y=y, color=color)
    p2.circle(x={'value': year, 'transform': Jitter(width=1)}, y=y, color=color)

output_file("jitter.html")

show(column(p1, p2))