Hello there,
I am trying to modify this example (http://bokeh.pydata.org/en/latest/docs/gallery/brewer.html), so as to have timedates or strings on the x-axis instead of numeric values. I have tried the modifications recommended at SO (https://stackoverflow.com/questions/42426410/bokeh-patches-plot-with-dates-as-x-axis-shifts-the-ticks-one-to-the-right?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa), making the needed changes and so the code that I’ve been trying to implement is:
from bokeh.plotting import figure, show, output_file
from bokeh.palettes import brewer
from bokeh.io import show
from bokeh.models import FactorRange
N = 20
categories = [‘y’ + str(x) for x in range(10)]
data = {}
data[‘x’] = np.arange(1,N+1)
for cat in categories:
data[cat] = np.random.randint(10, 100, size=N)
df = pd.DataFrame(data)
df = df.set_index([‘x’])
def stacked(df, categories):
areas = dict()
last = np.zeros(len(df[categories[0]]))
for cat in categories:
next = last + df[cat]
areas[cat] = np.hstack((last[::-1], next))
last = next
return areas
areas = stacked(df, categories)
colors = brewer[“Spectral”][len(areas)]
x2 = np.hstack((data[‘x’][::-1], data[‘x’]))
timesteps = [str(x.date()) for x in pd.date_range(‘1950-01-01’, ‘1951-08-01’, freq=‘MS’)]
p = figure(x_range=FactorRange(factors=timesteps), y_range=(0, 800))
p.grid.minor_grid_line_color = ‘#eeeeee’
p.patches([x2] * len(areas), [areas[cat] for cat in categories],
color=colors, alpha=0.8, line_color=None)
p.xaxis.major_label_orientation = np.pi/4
show(p)
However, this is not working anymore.
Does anyone have any idea on some possible fixes?
Thanks