This skill generates and executes data visualizations from absolute path data sources, returning artifacts and enabling inspection of dataframes and plots.
npx playbooks add skill robdmc/claude_skills --skill code
This skill directly executes visualizations. The calling agent provides a visualization spec along with data context, and the skill:
viz_runner.py helperKey pattern:
Caller (with data context) → Skill (infers data loading, generates script, executes) → Plot appears
The caller does NOT need to write any execution code. The skill handles everything.
The calling agent should provide:
/full/path/to/operational_forecast.ddb, table forecast, columns month, members"SELECT * FROM forecast WHERE year >= 2024"df = pd.read_parquet('/full/path/to/data.parquet')"/tmp/data.csv with columns X, Y, Z"CRITICAL: Absolute Paths Required
The viz_runner.py executes scripts from /tmp/viz/, NOT the caller's working directory. All file paths in generated scripts MUST be absolute paths. The calling agent should:
./data.ddb or data.parquetExample - WRONG:
con = duckdb.connect('operational_forecast.ddb') # Will fail!
Example - CORRECT:
con = duckdb.connect('/Users/rob/projects/forecast/operational_forecast.ddb')
pop_bar, churn_trend). The runner ensures uniqueness.Before generating any code, analyze the user's request to determine the appropriate mode.
--show)Use when the user wants to see the data itself, not a visualization:
Action: Use --show flag. Do NOT generate plot code.
Use when the user wants a chart, graph, or visual representation:
Action: Generate matplotlib/seaborn code and pass via stdin.
If unclear (e.g., "show me X over time"), default to asking or interpret based on context:
--show first (it's cheaper), then offer to plotAll artifacts are managed in /tmp/viz/ via the helper script.
viz_runner.pypython /Users/rob/.claude/skills/viz/viz_runner.py [--id NAME] [--desc "Description"] << 'EOF'
<generated script>
EOF
The runner:
/tmp/viz/ if needed_2, _3, etc. if collision)plt.savefig('/tmp/viz/<id>.png', dpi=150, bbox_inches='tight') before plt.show()/tmp/viz/<id>.py/tmp/viz/<id>.jsonTerminal output:
Plot: pop_bar
"Bar chart of members by month"
png: /tmp/viz/pop_bar.png
Sidecar JSON (/tmp/viz/<id>.json):
{
"id": "pop_bar",
"desc": "Bar chart of members by month",
"png": "/tmp/viz/pop_bar.png",
"script": "/tmp/viz/pop_bar.py",
"created": "2025-01-22T11:31:00",
"pid": 46368
}
The caller can then:
To see all available visualizations:
python /Users/rob/.claude/skills/viz/viz_runner.py --list
Output:
ID Description Created
-------------- ----------------------------------- ----------------
pop_bar Bar chart of members by month 2025-01-22 11:31
churn_trend Monthly churn rate 2025-01-22 10:45
test_scatter - 2025-01-22 09:20
To remove all visualization files from /tmp/viz/:
python /Users/rob/.claude/skills/viz/viz_runner.py --clean
Output:
Cleaned 12 files from /tmp/viz
/tmp/viz/, not the caller's directory.--desc with a short summary): python /Users/rob/.claude/skills/viz/viz_runner.py --id suggested_name --desc "Short description of plot" << 'EOF'
<complete script>
EOF
Use seaborn for the statistical plot, matplotlib for customizations like reference lines.
figsize=(10, 6) or appropriate aspect ratiotight_layout() to prevent clippingalpha=0.3Request from caller:
/viz id=pop_bar
bar chart showing total_initial_members and total_final_members by month
with dashed vertical line at history/forecast boundary (Dec 2025 / Jan 2026).
Data from operational_forecast.ddb, forecast table.
Skill generates and executes:
python /Users/rob/.claude/skills/viz/viz_runner.py --id pop_bar --desc "Bar chart of members by month with forecast boundary" << 'EOF'
import duckdb
import matplotlib.pyplot as plt
import numpy as np
# Load data from DuckDB (MUST use absolute path!)
con = duckdb.connect('/Users/rob/projects/forecast/operational_forecast.ddb', read_only=True)
df = con.execute("""
SELECT month, total_initial_members, total_final_members
FROM forecast
ORDER BY month
""").df()
con.close()
# Create grouped bar chart
fig, ax = plt.subplots(figsize=(12, 6))
x = np.arange(len(df))
width = 0.35
bars1 = ax.bar(x - width/2, df['total_initial_members'], width, label='Initial Members', color='steelblue')
bars2 = ax.bar(x + width/2, df['total_final_members'], width, label='Final Members', color='coral')
# History/forecast boundary
boundary_idx = df[df['month'] == '2025-12'].index[0] + 0.5
ax.axvline(x=boundary_idx, color='gray', linestyle='--', linewidth=1.5, label='Forecast Start')
ax.set_xlabel('Month', fontsize=12)
ax.set_ylabel('Members', fontsize=12)
ax.set_title('Member Population by Month: Historical vs Forecast', fontsize=14)
ax.set_xticks(x)
ax.set_xticklabels(df['month'], rotation=45, ha='right')
ax.legend()
ax.grid(True, alpha=0.3, axis='y')
plt.tight_layout()
plt.show()
EOF
Runner output:
Plot: pop_bar
"Bar chart of members by month with forecast boundary"
png: /tmp/viz/pop_bar.png
Skill returns to caller:
> Plot generated successfully.
> - ID: pop_bar
> - Script: /tmp/viz/pop_bar.py
> - PNG: /tmp/viz/pop_bar.png
Do NOT automatically read the PNG into context after generating a plot.
Reading images consumes significant context tokens and is usually unnecessary. The plot window opens automatically via plt.show(), so the user can already see the visualization.
Only read the PNG into context when:
Instead of reading the PNG, offer to open it:
open /tmp/viz/pop_bar.png # macOS
This displays the image in the system viewer without consuming context tokens.
When refining an existing plot:
pop_bar_2)When a user asks to regenerate an existing plot (e.g., after data has changed):
Request: "regenerate pop_bar"
Run the saved script directly:
python /tmp/viz/pop_bar.py
The script already contains the hardcoded savefig path, so it overwrites the existing PNG.
Request: "regenerate the churn plot"
--list to find matching plotpython /tmp/viz/<id>.pyRequest: "regenerate a plot"
--list to show available plotsRegeneration does NOT require viz_runner.py - the saved .py scripts are self-contained and can be executed directly with python.
Generated scripts use plt.show() which works with the macosx backend for interactive display. The injected savefig() ensures a PNG copy is always saved before display.
The viz skill can extract data from marimo notebooks and generate plots without modifying the original notebook.
/tmp/viz/<id>.pycwd set to original notebook's directory (so relative paths work)python /Users/rob/.claude/skills/viz/viz_runner.py \
--marimo \
--notebook /path/to/notebook.nb.py \
--target-var df_forecast \
--id forecast_plot \
--desc "Monthly forecast visualization" \
<< 'EOF'
# Plotting code that uses df_forecast
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(df_forecast['date'], df_forecast['total_final_members'])
plt.show()
EOF
--marimo: Enable marimo notebook mode (required)--notebook: Path to the marimo notebook file (required)--target-var: Variable to extract from the notebook (required)--target-line: Optional line number for capturing intermediate state (for mutated variables)--id: Suggested ID for the visualization (optional)--desc: Description of the visualization (optional)--show: Show mode - print dataframe info to console instead of plotting (no stdin required)--rows: Number of rows to display in show mode (default: 5)Marimo notebooks encode dependencies explicitly:
The skill walks backwards from the target variable through the dependency graph to find all required cells.
When a variable is mutated within a cell, use --target-line to capture intermediate state:
@app.cell
def _(raw_data):
df = raw_data.copy() # line 45
df = df[df['value'] > 0] # line 46 - filtered
df = df.groupby('cat').sum() # line 47 - aggregated
return (df,)
Use --target-var df --target-line 46 to capture df after filtering but before aggregation.
Use --show to print dataframe info to console instead of generating a plot. Useful for quickly inspecting data at a specific point in the notebook pipeline.
python /Users/rob/.claude/skills/viz/viz_runner.py \
--marimo \
--notebook /path/to/notebook.nb.py \
--target-var df \
--show \
--rows 10
Output:
Shape: (12345, 5)
Columns: ['date', 'profile_id', 'kind', 'state', 'channel_type']
Dtypes:
date datetime64[ns]
profile_id int64
kind object
state object
channel_type object
First 10 rows:
date profile_id kind state channel_type
0 2021-01-01 123456 monthly CA organic
1 2021-01-02 123457 monthly TX paid
...
No stdin (plot code) is required for show mode - it only prints dataframe metadata and contents.
User request:
> "Plot the member forecast over time from the operational forecast notebook"
Agent workflow:
python /Users/rob/.claude/skills/viz/viz_runner.py \
--marimo \
--notebook /Users/rob/repos/project/forecast.nb.py \
--target-var df_deliverable \
--id member_forecast \
--desc "Historical and forecast members" \
<< 'EOF'
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(12, 6))
ax.plot(df_deliverable['date'], df_deliverable['total_final_members'])
ax.set_xlabel('Date')
ax.set_ylabel('Members')
ax.set_title('Member Population Over Time')
plt.tight_layout()
plt.show()
EOF
/tmp/viz/uv run python if the notebook directory contains pyproject.toml or uv.lockWeekly roundup of top Claude Code skills, MCP servers, and AI coding tips.