So I put the data that I am using in a csv file with “;” separator. Here is my example now, it should be much easier to work with:
from bokeh.plotting import figure, output_file, show
import bokeh as bk
import pandas as pd
import colorcet as cc
test_data = pd.read_csv("./example Data bokeh.csv" ,sep=";")
def stacked_area_plot(data, titre, value, width, height, metabolite=None, condition=None, time=None):
#Commençons par la préparation de data
bk.plotting.output_file(filename = titre + ".html", title = titre + ".html")
stackdf = data[((metabolite is None) | (data['metabolite'] == metabolite)) & (data['condition'].isin(condition)) & (data['time'].isin(time))]
stackpivot = stackdf.pivot(index='ID', columns='isotopologue', values=value)
stackpivot.columns = stackpivot.columns.astype(str)
mysource = bk.models.ColumnDataSource(data=stackpivot)
mystackers = stackpivot.columns.tolist()
colors = cc.glasbey_dark[:len(mystackers)]
TOOLTIPS = [
("", "<strong>@ID</strong>"),
("isotopologue", "$name"),
("ID", "@$name"),
]
plot = figure(
width=width,
height = height,
tools="save,wheel_zoom,reset,hover",
tooltips=TOOLTIPS
)
plot.varea_stack(mystackers, x = "ID", color=colors, source=mysource)
print(stackpivot)
show(plot)
stacked_area_plot(test_data, "Example", "corrected_area", width=1000, height=600, metabolite = "2_3-PG", condition =["A", "B", "AB", "Cont"], time =["0", "24", "48"] )
Thanks in advance!