Make it interactive using panel
import panel as pn
pn.extension()#generalize function
def plot_sales(labels = df_sales['month'], location = " Drenthe", years = ['2020']):
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
n = len(years)
x = np.arange(len(labels))
pos = x - width/n
color = {'2019':'lightgrey', '2020':'grey'}
for year in years:
sales = df_sales[int(year)]
ax.bar(pos, sales, width, label=year, color = color[year])
pos = pos + width
ax.set_ylabel('gemiddeld aantallen verkocht')
ax.set_title('Verkoop in' + location)
ax.legend()
ax.set_xticks(x)
ax.set_xticklabels(labels)
plt.gcf().autofmt_xdate(rotation=90, which = 'major', ha="center")
plt.figsize=(8, 6)
fig.tight_layout()
########## return a panel object! ########
mpl_pane = pn.pane.Matplotlib(fig)
return mpl_pane
Making the panel nice with a template

Last updated