I would recommend using HoloViz Panel.
You can use matplotlib, bokeh, plot, altair or your favorite plotting library.
Here I’m using hvplot because it is easy to use and you get interactive plots.
app.py
import hvplot.pandas # Could be any plotting library
import pandas as pd
wide_data = pd.DataFrame({
"CODE": ["A", "B", "C"],
"vPoint1_R4": [357, 247, 232],
"vPoint2_R4": [430, 365, 285],
"vPoint3_R4": [502, 448, 360],
"vPoint4_R4": [539, 477, 398],
"step1": [15, 15, 15],
"step2": [30, 30, 30],
"step3": [45, 45, 45],
"step4": [60, 60, 60],
})
def to_tidy_data(wide_data):
ydata = pd.melt(wide_data, id_vars=["CODE"], value_vars=["vPoint1_R4", "vPoint2_R4", "vPoint3_R4", "vPoint4_R4"], value_name="y", var_name="item")
ydata["item"]=ydata["item"].str[-4]
xdata = pd.melt(wide_data, id_vars=["CODE"], value_vars=["step1", "step2", "step3", "step4"], value_name="x", var_name="item")
xdata["item"]=xdata["item"].str[-1]
data = pd.merge(xdata, ydata, on=["CODE", "item"])
return data
tidy_data = to_tidy_data(wide_data)
def plot(index):
if not index:
return "No row selected"
code = wide_data.iloc[index].CODE.iloc[0]
filtered_data = tidy_data[tidy_data["CODE"]==code]
return filtered_data.hvplot.scatter(x="x", y="y")
import panel as pn
pn.extension(sizing_mode="stretch_width")
table = pn.widgets.Tabulator(wide_data, height=125, theme="fast", selectable=1, )
interactive_plot = pn.bind(plot, index=table.param.selection)
pn.template.FastListTemplate(
site="Awesome Panel", title="Table selections",
main=[table, pn.panel(interactive_plot, height=350)]
).servable()
pip install pandas hvplot panel
panel serve app.py --autoreload --show
For inspiration check out my site awesome-panel.org.