Create an empty Element onto which I can dynamically overlay stuff?

I’m looking to create an empty Element, onto which other elements can be added/overlaid.
What should I write on the line with comments in the chunk of code below?

import holoviews as hv
import pandas as pd
df = pd.DataFrame({'i':[0,1,2],'A':[1,2,3],'B':[4,5,6]})
fig = hv.Curve() # what if I simply want an empty element, without attaching it to a dataset?
for series_name in ['A','B']:
    fig *= hv.Curve(df, 'i', series_name)

I know I can create the first element, and then add subsequent ones, but I don’t want to for stylistic reasons.

Fig = hv.Curve([]) #like this maybe?

1 Like

Thank you! This works.

Although it does contain an empty plot which is not ideal.

>>> print(fig)
:Overlay
   .Curve.I   :Curve   [x]   (y)
   .Curve.II  :Curve   [i]   (A)
   .Curve.III :Curve   [i]   (B)

I’m opting for the reduce based solution below, which does not have this problem:

from functools import reduce
import operator
import holoviews as hv
import pandas as pd
df = pd.DataFrame({'i':[0,1,2],'A':[1,2,3],'B':[4,5,6]})
elements = [ hv.Curve(df, 'i', series_name) for series_name in ['A','B'] ]
fig = reduce(operator.mul, elements)
1 Like

A more elegant way is using hv.Overlay

import holoviews as hv
import pandas as pd
df = pd.DataFrame({'i':[0,1,2],'A':[1,2,3],'B':[4,5,6]})
fig = hv.Overlay([ hv.Curve(df, 'i', series_name) for series_name in ['A','B'] ])
2 Likes

Indeed, this handles empty list better than what I suggested.
Thank you!