
Hello,
I am working on a project where I want to show an more or less empty figure and plot simple xy data upon loading a file. The way I implemented it so far is to create a dummy ColumnDataSource which I want to update with the data from the file. I manage to load my data into a data frame.
The problem I encounter is, that I am not able to pass the data frame into my source for plotting. My code is shown below:
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.io import show, output_notebook
from bokeh.io import curdoc
from bokeh.models.widgets import FileInput
output_notebook()
def upload_fit_data(attr, old, new):
print("fit data upload succeeded")
newdat=pd.read_csv(file_input.filename, delimiter=' ')
newdat['y']=100*newdat['y']/np.max(newdat['y'])
print(newdat)
loaddat.data=ColumnDataSource.from_df(newdat)
file_input = FileInput(accept=".csv,.json,.txt")
file_input.on_change('value', upload_fit_data)
d = {'x': [0], 'y': [0]}
df=pd.DataFrame(data=d)
loaddat=ColumnDataSource(df)
def plot(doc):
d = {'x': [0], 'y': [99]}
df=pd.DataFrame(data=d)
loaddat=ColumnDataSource(df)
doc.add_root(file_input)
p=figure(plot_width = 950, plot_height = 600,
x_axis_label = 'x', y_axis_label = 'y [%]', tools=['pan,wheel_zoom, box_zoom, reset'],
toolbar_location='below',)
p.line(x='x', y='y', color='black', source=loaddat)
doc.add_root(p)
show(plot)
with a data.txt as follows:
x y
1.014 550
1.044 094
1.073 639
1.103 185
1.836 240
1.866 225
1.896 210
1.926 197
1.956 186
1.986 176
When I print my newdat everything looks fine, yet the plot does not get updated. I don’t really understand why.
Thanks in advance for your help with this rookie question!
Daniel

