'hvplot graphs with for loop

I am trying to create hvplot graphs with a for a loop but it seems not to working.

for i in [2019,2020,2021]:
    CompanyYear= Company[Company['Year']==i]
    filtered.hvplot.bar(x='CompanyID', y='Sales', rot=90)

I know that with matplotlib you have to use plt.show().



Solution 1:[1]

If you are trying to achieve three plots side by side, one for each year, I suggest you tp use the holoviews package. This will work:

import holoviews as hv

hv.Layout([Company[Company.Year==i].hvplot.bar(x='CompanyID', y='Sales',rot=90, label=str(i)) for i in [2019, 2020, 2021]])

Otherwise, if you want all of them in the same plot, you have to do an Overlay:

hv.Layout([Company[Company.Year==i].hvplot.bar(x='CompanyID', y='Sales',rot=90, label=str(i)) for i in [2019, 2020, 2021]])

If you run these commands inside Jupyter Lab/Notebook as the last line of a cell the plots will show up.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1