plotnine
plotnine copied to clipboard
Computing histogram with datetime axis throws TypeError: can't compare offset-naive and offset-aware datetimes
This is a minimal example that produces the error. Leaving out any single row in the data table will result in the expected plot without throwing the error. Similarly, specifying + gg.scale_x_datetime(breaks='12 hours', date_labels='%m-%d %H:%M') will produce a plot without errors.
import pandas as pd
import plotnine as gg
Registration_Time = '''
2022-10-19 04:42:04
2022-10-19 10:16:29
2022-10-19 13:27:09
2022-10-19 14:40:24
2022-10-19 15:20:31
2022-10-19 15:47:18
2022-10-19 17:00:23
2022-10-19 22:45:01
'''.strip().splitlines()
org = '''
other
wcm
wcm
cu
wcm
wcm
cu
cu
'''.strip().splitlines()
df = pd.DataFrame({'Registration_Time':Registration_Time, 'org':org})
df['Registration_Time'] = pd.to_datetime(df['Registration_Time'])
df['org'] = pd.Categorical(df.org, categories=['wcm', 'cu', 'other'])
plot_df = (
df
.sort_values("Registration_Time")
)#.iloc[:-1]
# plotnine to plot (using grammar of graphics like ggplot2)
plot = (
gg.ggplot(plot_df, gg.aes(x='Registration_Time', fill='org', group='org'))
+ gg.geom_histogram(binwidth=4/24, position='stack', color='black', show_legend=False)
)
plot.show()