Certainly! Below is an example of how you can create a stacked bar chart using Plotly to visualize the daily counts of the different keyword categories from your daily_analysis_results DataFrame.
The stacked bar will show:
- LLM Event Keywords Daily Count
- Script Event Keywords Daily Count
- LLM Event Keywords Daily Count (Anomalous Posts)
- Script Event Keywords Daily Count (Anomalous Posts)
all stacked per day.
import plotly.graph_objects as go
# Sample DataFrame (replace this with your actual DataFrame)
# daily_analysis_results = pd.read_csv('your_data.csv')
fig = go.Figure()
fig.add_trace(go.Bar(
x=daily_analysis_results['Date'],
y=daily_analysis_results['LLM Event Keywords Daily Count'],
name='LLM Event Keywords Daily Count'
))
fig.add_trace(go.Bar(
x=daily_analysis_results['Date'],
y=daily_analysis_results['Script Event Keywords Daily Count'],
name='Script Event Keywords Daily Count'
))
fig.add_trace(go.Bar(
x=daily_analysis_results['Date'],
y=daily_analysis_results['LLM Event Keywords Daily Count (Anomalous Posts)'],
name='LLM Event Keywords Daily Count (Anomalous Posts)'
))
fig.add_trace(go.Bar(
x=daily_analysis_results['Date'],
y=daily_analysis_results['Script Event Keywords Daily Count (Anomalous Posts)'],
name='Script Event Keywords Daily Count (Anomalous Posts)'
))
fig.update_layout(
barmode='stack',
title='Daily Keyword Counts (Stacked)',
xaxis_title='Date',
yaxis_title='Count',
xaxis=dict(tickangle=-45),
legend_title='Categories',
height=600,
width=900
)
fig.show()
Explanation:
- We add one
go.Bar trace per category.
barmode='stack' stacks the bars on top of each other.
tickangle=-45 rotates the x-axis labels for better readability.
- Adjust
height and width as needed.
If your Date column is not already a datetime type, you might want to convert it first:
daily_analysis_results['Date'] = pd.to_datetime(daily_analysis_results['Date'])
Let me know if you want me to help with any customization!