I am learning matplotlib
and ipywidgets
and attempt to design an interactive bar chart, such that the selected category can be highlighted.
Data Example
Assuming I have a dataframe:
import pandas as pd
import matplotlib.pyplot as plot
data = {"Production":[10000, 12000, 14000],
"Sales":[9000, 10500, 12000]}
index = ["2017", "2018", "2019"]
df = pd.DataFrame(data=data, index=index)
df.plot.bar(stacked=True,rot=15, title="Annual Production Vs Annual Sales")
The resulting stacked bar chart looks like below:
What I am after
If we select production
in the dropdown list, the blue bars will be highlighted by adding a box (or a frame) surrounding it. Similar should happen to Sales
if it is selected.
Question
I am not sure if ipywidgets
and matplotlib
are enough to fulfill this feature, or do we need other package to make it? If possible to do with those two packages, could anyone share some clues? Thanks!
Here is one quick way to do it with ipywidgets and matplotlib:
This is what you get from running the above code in the same Jupyter notebook cell: