1

The general notation for creating subplots with datashade/holoviews/Bokeh is using a '+' notation:

plot = plot1 + plot2 + plot3

However, I'm trying to generate plots inside a for loop like I can with Matplotlib. In Seaborn I can just do this to create subplots while incrementing through the dataframe:

fig, axes = plt.subplots(nrows=len(DF_cols), ncols=1, figsize=(10,10), sharex = True)

count = 0
for i in DF_cols:
     sns.lineplot(data=df[i], label=i, ax=axes[count])
     count += 1

return fig, axes

How do convert the method I have below for Datashade/Holoviews into a more automated process?

c1 = hv.Curve(df['T'])
c2 = hv.Curve(df['A'])
c3 = hv.Curve(df['B'])
c4 = hv.Curve(df['C'])
plot1 = dynspread(datashade(c1))
plot2 = dynspread(datashade(c2))
plot3 = dynspread(datashade(c3))
plot4 = dynspread(datashade(c4))
plot = (plot1 + plot2 + plot3 + plot4).cols(1)
plot

My initial approach was to use create a custom string to mimic the normal Datashade notation and running exec() on it, but that doesn't work when using inside functions or it encounters other errors eventually.

Stigma
  • 331
  • 1
  • 4
  • 15

1 Answers1

2

You can programmatically create layouts by passing a list of elements to hv.Layout. In this case, the following line should do the trick:

hv.Layout([plot1, plot2, plot3, plot4]).cols(1)
jlstevens
  • 201
  • 1
  • 2
  • Or, to account for all the code above, `hv.Layout([dynspread(datashade(hv.Curve(df[c]))) for c in ['T','A','B','C']]).cols(1)`. – James A. Bednar Jan 25 '19 at 14:24