I am trying to input a single .csv file that contains data from different packet streams (hence, different time values). I created a dataframe for each time and the data points/columns from each dataframe are plotted in single plot.
I converted the times to datetime format but, the first dataframe does not plot the correct format for the x-axis whereas the following ones do.
Note: there are 3 dataframes in this sample code and I tried trimming the rows to avoid some anomalous data points at the beginning.
colors = itertools.cycle(palette)
j = 0
tabs_df_list = []
## Creating source and figures for each telemetry point
for x in df_list:
j += 1
df_col_names = x.columns.to_numpy()
col_names = df_col_names.tolist()
x.iloc[:,0] = pd.to_datetime(x.iloc[:,0], unit='s', origin='unix')
#x.iloc[:,0] = x.iloc[:,0].dt.strftime('%d-%m-%Y %H:%M:%S')
present = datetime.datetime.now()
past = datetime.timedelta(days=365)
year = present - past
condition = (x.iloc[:,0] > year)
x = x[condition]
x = x.reset_index(drop=True)
x.iloc[:,0] = pd.to_datetime(x.iloc[:,0], unit='s', origin='unix')
source = "source"+str(j)
source = ColumnDataSource(x)
## Create a figure for each df
p = "p" + str(j)
p = figure(title = 'Test Report',
match_aspect = False,
toolbar_location = 'right',
x_axis_type = 'datetime',
height=750, width=1000,
x_axis_label = 'Time [hh:mm:ss]',
y_axis_label = 'Tlm value') # need to customize to tlm col
p.xaxis.major_label_orientation = pi/4
p.xaxis.formatter = DatetimeTickFormatter(
days=["%m/%d %H:%M:%S"],
months=["%m/%d %H:%M:%S"],
hours=["%m/%d %H:%M:%S"],
minutes=["%m/%d %H:%M:%S"],
seconds=["%m/%d %H:%M:%S"]
)
tabs_temp = []
items_list = []
k = 1
while k < len(col_names):
color = next(colors)
r = "r" + str(k)
r = p.line(x=col_names[0], y=col_names[k], source=source, line_width=2, line_color=color, name=col_names[k])
#r = p.scatter(x=col_names[0], y=col_names[k], source=source, legend_label=col_names[k])
legend_items = [(col_names[k], [r])]
items_list = items_list + legend_items
tab = [TabPanel(child=p, title=col_names[0])]
k += 1
p.add_tools(HoverTool(tooltips=tooltips))
legend = Legend(items=items_list
,location=(3, -25))
p.add_layout(legend, 'right')
tabs_df = "tabss" + str(j)
tabs_df = Tabs(tabs=tab)
tabs_df_list.append(tabs_df)
grid = gridplot (tabs_df_list, ncols=1)
#layout = column(date_range_slider, grid)
layout = column (grid)
show (layout)
# output settings
output_file('Test Plots_3.html', title = 'Test Data Plots_3') # Render to static HTML, or
output_notebook() # Render inline in a Jupyter Notebook
First plot:
Following plots:
Can someone illuminate on what is happening here? Occasionally, I get the warning: Name: TIME, Length: 3468, dtype: datetime64[ns]’ has type incompatible with float64, please explicitly cast to a compatible dtype first.