I am struggling to get the Jitter transform to behave properly with categorical plots. Was it not intended to work with this type?
import numpy as np
import pandas as pd
from bokeh.models import Jitter, ColumnDataSource, FactorRange
from bokeh.plotting import figure, show, output_file
from bokeh.layouts import row, column, widgetbox
np.random.seed()
letters = np.random.choice(list('abcde'), 40)
numbers = np.random.uniform(1,10, 40).round(1)
jitter = 0.3
df = pd.DataFrame(zip(letters,numbers), columns=['letters', 'numbers'])
cds = ColumnDataSource(df)
# I prefer to build categorical plots by instantiating a figure with an empty factor range.
# Figure 3 should demonstrate this is not contributing to the issue.
x_factor_range = FactorRange(factors=[])
fig1 = figure(title="Categorical with No Jitter", x_range=x_factor_range)
fig1.x_range.factors = list('abcde')
<details class='elided'>
<summary title='Show trimmed content'>···</summary>
#
fig2 = figure(title="Categorical with Jitter", x_range=x_factor_range)
fig2.x_range.factors = list('abcde')
fig3 = figure(title="Categorical with Jitter", x_range=list('abcde'))
# Specifying with DataSpec and no jitter.
fig1.circle(
x={'field': 'letters'},
y='numbers',
source=cds,
line_color='black',
line_alpha=1.0,
size=9
)
# Trying to jitter.
fig2.circle(
x={'field': 'letters', 'transform': Jitter(width=jitter)},
y='numbers',
source=cds,
line_color='black',
line_alpha=1.0,
size=9
)
# Try to jitter using a figure that was instantiated differently.
fig3.circle(
x={'field': 'letters', 'transform': Jitter(width=jitter)},
y='numbers',
source=cds,
line_color='black',
line_alpha=1.0,
size=9
)
output_file("jitter.html")
show(row(fig1, fig2, fig3))