# Prepare data - pivot to get all three metrics by date
metrics_pivot = df_total.pivot_table(
index='Date',
columns='Metric_Type',
values='Value_Thousands_m3',
aggfunc='sum'
).reset_index()
# Create subplots
fig2 = make_subplots(
rows=3, cols=1,
subplot_titles=(
'<b>Production Volume</b>',
'<b>Shipments Volume</b>',
'<b>Inventory Stocks</b>'
),
vertical_spacing=0.08,
shared_xaxes=True
)
# Production
fig2.add_trace(
go.Scatter(
x=metrics_pivot['Date'],
y=metrics_pivot['Production'],
fill='tozeroy',
fillcolor='rgba(46, 125, 50, 0.3)',
line=dict(color='#2E7D32', width=1.5),
name='Production',
hovertemplate='%{x|%b %Y}: %{y:,.0f} thousand m³<extra></extra>'
),
row=1, col=1
)
# Shipments
fig2.add_trace(
go.Scatter(
x=metrics_pivot['Date'],
y=metrics_pivot['Shipments'],
fill='tozeroy',
fillcolor='rgba(21, 101, 192, 0.3)',
line=dict(color='#1565C0', width=1.5),
name='Shipments',
hovertemplate='%{x|%b %Y}: %{y:,.0f} thousand m³<extra></extra>'
),
row=2, col=1
)
# Stocks
fig2.add_trace(
go.Scatter(
x=metrics_pivot['Date'],
y=metrics_pivot['Stocks'],
fill='tozeroy',
fillcolor='rgba(230, 81, 0, 0.3)',
line=dict(color='#E65100', width=1.5),
name='Stocks',
hovertemplate='%{x|%b %Y}: %{y:,.0f} thousand m³<extra></extra>'
),
row=3, col=1
)
# Update layout
fig2.update_layout(
title=dict(
text='<b>Lumber Industry Performance</b><br><sup>Monthly Production, Shipments & Inventory (2014-2024)</sup>',
font=dict(size=16)
),
template='plotly_white',
showlegend=False,
height=700,
margin=dict(l=60, r=20, t=100, b=40)
)
# Update y-axes
fig2.update_yaxes(title_text='Thousand m³', row=1, col=1)
fig2.update_yaxes(title_text='Thousand m³', row=2, col=1)
fig2.update_yaxes(title_text='Thousand m³', row=3, col=1)
fig2.show()
print("\n")
print(style.BOLD + "Dashboard Insights" + style.END)
print("""
This dashboard reveals the operational dynamics of the lumber industry:
1. PRODUCTION-SHIPMENT ALIGNMENT:
Production and shipments track very closely, indicating efficient
supply chain management with minimal inventory buildup.
2. STOCK STABILITY:
Inventory levels remain relatively stable (5,000-6,500 thousand m³)
despite production fluctuations, showing good inventory control.
3. SEASONAL SYNCHRONIZATION:
All three metrics show similar seasonal patterns, suggesting the
industry responds dynamically to market demand cycles.
4. COVID RESPONSE (2020):
Notice how stocks initially spiked when shipments dropped (demand
shock), then normalized as production adjusted.
""")