A Python utility for creating treemap visualizations from CSV data files. Generates both PNG and SVG output files with customizable labels, values, and formatting.
- Generate treemaps from CSV data
- Customizable column mapping for labels and values
- Optional value prefix (e.g., "$" for monetary values)
- Output in both PNG and SVG formats
- Clean, professional visualization with formatted numbers
- Python 3.x
- uv (package manager)
- Dependencies: pandas, plotly
Install dependencies using uv:
uv pip install pandas plotly kaleidouv run treemap-generator.py <csv_file> <title> [options]csv_file- Path to your CSV data file (required)title- Title for the treemap (required)
-l,--label-col- Column name for labels (default: 'Item')-v,--value-col- Column name for values (default: 'Total')-o,--output- Output file prefix (default: 'treemap')-p,--prefix- Optional prefix for values (e.g., "$" for money)
uv run treemap-generator.py data.csv "My Treemap"Expects CSV with columns named 'Item' and 'Total'.
uv run treemap-generator.py sales.csv "Sales Data" --label-col Product --value-col Revenueuv run treemap-generator.py budget.csv "Budget Overview" -l Category -v Amount -p "$"uv run treemap-generator.py data.csv "Q4 Results" -o q4_resultsThis creates q4_results.png and q4_results.svg.
uv run treemap-generator.py expenses.csv "Department Expenses" \
--label-col Department \
--value-col Total_Spent \
--output dept_expenses \
--prefix "$"Your CSV file should have at least two columns:
- One for labels (e.g., names, categories)
- One for numeric values
Example CSV:
Item,Total
Software,125000
Hardware,85000
Services,45000
Training,15000
Or with custom column names:
Category,Amount
Marketing,250000
Engineering,500000
Sales,180000
The script generates two files:
<output_prefix>.png- Raster image<output_prefix>.svg- Vector image
Treemap tiles display:
- Bold label (top)
- Formatted value with optional prefix (bottom)
Values are formatted with comma separators exactly as provided in the CSV (e.g., "$125,000" or "$125,000.50").
- If a specified column is not found, the script will display available columns and exit
- Without the
--prefixoption, values display without any prefix symbol - The prefix can be any string (e.g., "$", "€", "£", "¥")
The script validates:
- CSV file exists
- Specified columns exist in the CSV
- Provides helpful error messages with available column names
View all options:
uv run treemap-generator.py --help