 How to create a stem plot [solved]

For anyone needing to create a ‘stem plot’, here’s how I did it:

I have the result of a Fourier transform of some data (‘sine_sig’) in a dataframe called ‘freq_df’. It has columns ‘period’ and ‘power’. I create a scatter plot of the data and then overlay polygons that are plotted (approximately) correctly. Making the width of the polygons very small makes the offset almost unnoticeable but you could adjust the polygon function to make everything suit.

def rectangle(x=0, y=0, width=.005, height=.05):
return np.array([(x, y), (x+width, y), (x+width, y+height), (x, y+height)])

fft = hv.Scatter(freq_df).opts(color='red', xlabel='Period',
default_tools=['hover', 'reset', 'box_zoom'],logx=True,
width=900)

stems = hv.Polygons([{('x', 'y'): rectangle(x, y=0, height=y)}
for x, y in freq_df.to_records(index=False)]).opts(color='black',logx=True)

spectrum = hv.Overlay([stems, fft])

actual = hv.Curve(pd.DataFrame({'t': t, 's': sine_sig})
).opts(width=900, default_tools=['hover', 'reset', 'box_zoom'])

hv.Layout([actual, spectrum]).cols(1).opts(width=900)

Result:

Or you could do that (yeah, did not see hv.Spikes)