The code below does not work.
The
p.y_range = FactorRange(factors=cats)
cannot set the y-axis range.
However, if I use:
p = figure( y_range=FactorRange(factors=list(cats)), width=900, x_range=(-5, 105), toolbar_location=None)
it works!
I need to set the y-range after the figure initialisation though, for the purposes of my application. Any thoughts?
Thank you in advance
import colorcet as cc
from numpy import linspace
from scipy.stats.kde import gaussian_kde
from scipy import stats
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show
from bokeh.sampledata.perceptions import probly
from bokeh.models import Div, ColumnDataSource, FactorRange
def ridge(category, data, scale=20):
return list(zip([category]*len(data), scale*data))
cats = list(reversed(probly.keys()))
palette = [cc.rainbow[i*15] for i in range(17)]
x = linspace(-20,110, 500)
source = ColumnDataSource(data=dict(x=x))
p = figure( width=900, x_range=(-5, 105), toolbar_location=None)
p.y_range = FactorRange(factors=cats)
for cat in reversed(cats):
pdf = gaussian_kde(list(probly[cat]))
y= pdf(x)
y = ridge(cat, pdf(x))
source.data[cat] = y
p.patch('x', cat, source=source, alpha=0.6, line_color="black",)
show(p)