0

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().

benson23
  • 16,369
  • 9
  • 19
  • 38
j_90
  • 79
  • 1
  • 6

1 Answers1

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.

gioarma
  • 418
  • 2
  • 15