pythonbeginner
Matplotlib Charts for Data Pipelines
Generate and save charts programmatically from pipeline output using matplotlib.
pythonPress ⌘/Ctrl + Shift + C to copy
import matplotlib
matplotlib.use('Agg') # non-interactive backend
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
df = pd.DataFrame({'month': pd.period_range('2024-01', periods=12, freq='M'),'revenue': np.random.randint(10000, 50000, 12)})
fig, axes = plt.subplots(1, 2, figsize=(12, 4))
# Bar chart
axes[0].bar(df['month'].astype(str), df['revenue'], color='steelblue')
axes[0].set_title('Monthly Revenue')
axes[0].tick_params(axis='x', rotation=45)
# Rolling trend
df['ma3'] = df['revenue'].rolling(3).mean()
axes[1].plot(df['month'].astype(str), df['revenue'], label='Revenue')
axes[1].plot(df['month'].astype(str), df['ma3'], label='3M MA', linestyle='--')
axes[1].legend()
axes[1].tick_params(axis='x', rotation=45)
plt.tight_layout()
plt.savefig('revenue_report.png', dpi=150)
print('Chart saved')Use Cases
- automated reports
- pipeline visualisation
- BI charting
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
sqladvanced
SQL Window Functions for Analytics
Advanced SQL window functions for running totals, rankings, moving averages, and gap analysis.
Best for: Building analytics dashboards with running totals
#sql#window-functions
pythonbeginner
Pandas Styled DataFrame Report
Apply conditional formatting to a pandas DataFrame for styled HTML reports with highlighting.
Best for: executive reporting
#pandas#styling
pythonbeginner
Pandas Pivot Table Summary
Create multi-level summary pivot tables from transactional data using pd.pivot_table.
Best for: sales reporting
#pandas#pivot-table
sqlbeginner
String Aggregation with GROUP BY
Concatenate grouped values into comma-separated strings using STRING_AGG with ordering and filtering.
Best for: Tag lists per item
#aggregation#string-agg