I use something like the following code (taken from here) to generate data (from external instruments). I had no prior experience with holoviews or pandas, and started simply by plotting the data (of the first instrument) as it came in using a DynamicMap
. Now I have many more instruments, and realize to my embarrassment, that I don’t know how to plot any column other than the default first two.
How do I plot the other column versus the first?
I guess I could just duplicate everything (Using a second buffer), but there has to be an easier way.
import numpy as np
import pandas as pd
import holoviews as hv
hv.extension('bokeh')
from holoviews.streams import Buffer
from datetime import datetime
class FakeInstrument(object):
def __init__(self, offset=0.0):
self.offset = offset
def set_offset(self, value):
self.offset = value
def read_data(self):
return np.random.random() + self.offset
instrument = FakeInstrument()
def make_df(data_frequency=0.0, data_phaseshift=0.0, data_magnitude=0.0):
return pd.DataFrame(data={'Frequency (Hz)': data_frequency, 'Phase shift (deg)': data_phaseshift, 'Magnitude (V)': data_magnitude}, index=[datetime.now()])
empty_reference_df = pd.DataFrame(columns=make_df().columns)
buffer_length = 10
buffer = Buffer(empty_reference_df, length=buffer_length, index=False)
plot1 = hv.DynamicMap(hv.Curve, streams=[buffer])
for f in range(buffer_length):
value1 = instrument.read_data()
value2 = instrument.read_data()
b = make_df(f, value1, value2)
buffer.send(b)
plot1#Looks okay. By default the first two columns are plotted
plot1.dframe()#looks okay
#plot1.dframe().to_csv('./tmp.csv', index=True, sep=' ')#Saving the whole DataFrame to a single file