I am trying to plot data from my DataFrame using bokeh and plot is always empty. Below is my function.
def statplot(stats_df,plotname):
try:
source_df = ColumnDataSource(data=stats_df.sort_values(by=['log_time']))
print(source_df.data)
output_file(plotname,'General Statistics')
datetime_tick_formats = {
key: ["%a %b %d %H:%M:%S"]
for key in ("seconds", "minsec", "minutes", "hourmin", "hours", "days")}
hover1 = HoverTool(tooltips=[('Date','@log_time{%Y-%m-%d %H:%M:%S}'),('Value','@PrivateMem')],formatters = {'@log_time':'datetime'})
p1 = figure(title="PrivateMemory MB",plot_width=800, plot_height=400,x_axis_type="datetime")
p1.xaxis.axis_label="Time"
p1.yaxis.axis_label="MB"
p1.xaxis.formatter = DatetimeTickFormatter(**datetime_tick_formats)
p1.line(x='log_time',y='PrivateMem',source=source_df,line_width=2,color="red",legend_label='Private Memory')
p1.add_tools(hover1)
plot = gridplot([p1],ncols=1)
save(plot)
I have the print source.data to verify if my ColumnDataSource has any values and it looks like it does. Below is the sample data
{'index': array([ 550, 551, 552, ..., 1658, 1659, 1660]), 'log_time': array(['2021-02-19T17:08:27.000000000', '2021-02-19T17:10:59.000000000',
'2021-02-19T17:11:59.000000000', ...,
'2021-02-24T08:33:38.000000000', '2021-02-24T08:34:38.000000000',
'2021-02-24T08:35:38.000000000'], dtype='datetime64[ns]'), 'PrivateMem': array([' 33', ' 67', ' 72', ..., ' 91', ' 90', ' 90'], dtype=object), 'PagedMem': array([' 33', ' 67', ' 72', ..., ' 91', ' 90', ' 90'], dtype=object), 'ThreadCount': array([' 36', ' 54', ' 49', ..., ' 44', ' 45', ' 45'], dtype=object), 'HandleCnt': array([' 1134', ' 2214', ' 2232', ..., ' 2498', ' 2488', ' 2498'],
dtype=object)}
Any ideas what I am doing wrong in function that is preventing the values to be plotted?
Issue was with values in the df with space. Once we removed the space in the values Bokeh was able to plot without any issues.