powerbi-python-visuals
Skill3 starsChanged 7 months agoMITView on GitHub
Python visual creation and matplotlib/seaborn patterns for PBIR reports. Automatically invoke when the user mentions "Python visual", "matplotlib in Power BI", "seaborn in Power BI", "pythonVisual", or asks to "create a Python visual", "add a matplotlib chart", "write a Python visual script".
- Installs packages
In this repository58 other files it gives its agents.
- powerbi-audit-tenant-settingsSkill
- powerbi-bpa-rulesSkill
- powerbi-connect-pbidSkill
- powerbi-connectSkill
- powerbi-create-pbi-reportSkill
- powerbi-c-sharp-scriptingSkill
- powerbi-custom-visualsSkill
- powerbi-cyber-securitySkill
- powerbi-data-catalog-lineageSkill
- powerbi-data-governance-traceabilitySkill
- powerbi-data-transformationSkill
- powerbi-dax-masterySkill
- powerbi-dax-performanceSkill
- powerbi-daxSkill
- powerbi-deneb-visualsSkill
- powerbi-doctorSkill
- powerbi-duckdb-lakehouseSkill
- powerbi-fabric-appsSkill
- powerbi-fabric-app-templatesSkill
- powerbi-fabric-capacitySkill
- powerbi-fabric-cliSkill
- powerbi-fabric-pipelinesSkill
- powerbi-fabricSkill
- powerbi-lineage-analysisSkill
- powerbi-measure-glossarySkill
- powerbi-medallion-architectureSkill
- powerbi-modelSkill
- powerbi-modifying-theme-jsonSkill
- powerbi-paginated-reportsSkill
- powerbi-pbi-cliSkill
- powerbi-pbip-formatSkill
- powerbi-pbir-cliSkill
- powerbi-pbir-format-enhancedSkill
- powerbi-performance-scaleSkill
- powerbi-power-querySkill
- powerbi-project-managementSkill
- powerbi-refresh-semantic-modelSkill
- powerbi-report-authoringSkill
- powerbi-report-conversionSkill
- powerbi-report-designSkill
- powerbi-reportSkill
- powerbi-report-structureSkill
- powerbi-report-themingSkill
- powerbi-review-reportSkill
- powerbi-review-semantic-modelSkill
- powerbi-r-visualsSkill
- powerbi-security-rlsSkill
- powerbi-source-integrationSkill
- powerbi-spark-livySkill
- powerbi-standardize-naming-conventionsSkill
- powerbi-star-schema-modelingSkill
- powerbi-svg-visualsSkill
- powerbi-te2-cliSkill
- powerbi-te-cliSkill
- powerbi-te-docsSkill
- powerbi-testing-validationSkill
- powerbi-time-series-dataSkill
- powerbi-tmdlSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 29
Create the visual.json file manually (see pbir-format skill in the pbip plugin for JSON structure) with visualType: pythonVisual, field …
- Very specific: line 48
Only the last plt.show() call renders.
- Very specific: line 52
Before presenting the script to the user, dispatch the python-reviewer agent to validate correctness and provide design feedback.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Python Visuals in Power BI (PBIR)
Report modification requires tooling. Two paths exist:
pbirCLI (preferred) -- use thepbircommand and thepbir-cliskill. Install withuv tool install pbir-cliorpip install pbir-cli. Check availability withpbir --version.- Direct JSON modification -- if
pbiris not available, use thepbir-formatskill (pbip plugin) for PBIR JSON structure and patterns. Validate every change withjq empty <file.json>.If neither the
pbir-cliskill nor thepbir-formatskill is loaded, ask the user to install the appropriate plugin before proceeding with report modifications.
Python visuals execute matplotlib/seaborn scripts to render static PNG images on the Power BI canvas. Prefer seaborn over raw matplotlib for cleaner syntax and better defaults -- it handles most chart types with less code.
Visual Identity
- visualType:
pythonVisual - Data role:
Values(columns and measures, multiple allowed) - Data variable:
dataset(pandas DataFrame, auto-injected) - Row limit: 150,000 rows
- Output: Static PNG at 72 DPI -- no interactivity
Workflow: Creating a Python Visual
Step 1: Add the Visual
Create the visual.json file manually (see pbir-format skill in the pbip plugin for JSON structure) with visualType: pythonVisual, field bindings for the columns and measures you need (use Values:Table.Column or Values:Table.Measure format), and position/size as required.
Step 2: Write the Script
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(8, 4))
ax.bar(dataset["Date"], dataset["Sales"], color="#5B8DBE")
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
plt.tight_layout()
plt.show() # MANDATORYCritical rules:
plt.show()is mandatory as the final line -- nothing renders without itdatasetis auto-injected as a pandas DataFrame; do not create it- Column names match the
nativeQueryRef(display name) from field bindings - Only the last
plt.show()call renders; multiple figures not supported
Step 2b: Review
Before presenting the script to the user, dispatch the python-reviewer agent to validate correctness and provide design feedback.
Step 3: Inject the Script
Set the script content in the visual's objects.script[0].properties.source literal value (see PBIR Format section below).
Escaping rules for visual.json injection:
The script must be encoded as a single-quoted DAX literal string inside expr.Literal.Value:
- Newlines in the script become
\nin the JSON string - Double quotes inside the script (e.g.,
"#5B8DBE") become\"in the JSON string - The entire script is wrapped in single quotes:
'import matplotlib...\nplt.show()' - See
examples/visual/for a complete real-world visual.json showing this encoding
Step 4: Validate
Validate JSON syntax with jq empty <visual.json> and inspect the visual.json to confirm script content and field bindings.
PBIR Format
Scripts are stored in visual.objects.script[0].properties:
{
"source": {"expr": {"Literal": {"Value": "'import matplotlib.pyplot as plt\\n...\\nplt.show()'"}}},
"provider": {"expr": {"Literal": {"Value": "'Python'"}}}
}The CLI handles all escaping automatically.
Supported Libraries
Power BI Service (Python 3.11)
| Package | Version | Purpose |
| matplotlib | 3.8.4 | Primary plotting |
| seaborn | 0.13.2 | Statistical visualization |
| numpy | 2.0.0 | Numerical computing |
| pandas | 2.2.2 | Data manipulation |
| scipy | 1.13.1 | Scientific computing |
| scikit-learn | 1.5.0 | Machine learning |
| statsmodels | 0.14.2 | Statistical models |
| pillow | 10.4.0 | Image processing |
Not supported: plotly, bokeh, altair (networking blocked in Service).
Full package list: https://learn.microsoft.com/power-bi/connect-data/service-python-packages-support
Desktop
Any locally installed package works without restriction.
Best Practices
- Always call
plt.show()-- mandatory, must be the final line - Use
figsize=(w, h)to match container aspect ratio (72 DPI output) - Remove chart chrome --
ax.spines["top"].set_visible(False)etc. - Use hex colors matching the report theme
- Keep scripts simple -- 5-min timeout Desktop, 1-min Service
- Minimize transforms -- do heavy computation in DAX/Power Query instead
- Use
try/exceptfor robustness in production scripts - Copy data first --
data = dataset.copy()before manipulation
Limitations
| Constraint | Desktop | Service |
| Output | Static PNG, 72 DPI | Static PNG, 72 DPI |
| Timeout | 5 minutes | 1 minute |
| Row limit | 150,000 | 150,000 |
| Payload | -- | 30 MB |
| Networking | Unrestricted | Blocked |
| Gateway | Personal only | Personal only |
| Cross-filter FROM | Not supported | Not supported |
| Receive cross-filter | Yes | Yes |
| Publish to web | Not supported | Not supported |
| Embed (app-owns-data) | Ending May 2026 | Ending May 2026 |
Script Structure Template
import matplotlib.pyplot as plt
import numpy as np
# 1. Guard against empty data
if dataset.empty:
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
ax.text(0.5, 0.5, "No data available", ha='center', va='center', fontsize=14, color='#888888')
ax.axis('off')
plt.show()
else:
# 2. Data preparation (dataset is auto-injected)
data = dataset.copy()
# 3. Create figure with explicit size
fig, ax = plt.subplots(figsize=(8, 4))
# 4. Plot
ax.plot(data["X"], data["Y"], color="#5B8DBE", linewidth=2)
# 5. Style
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.grid(axis="y", alpha=0.3)
# 6. Layout and render
plt.tight_layout()
plt.show()When to Use Python Visuals
Python visuals are appropriate for statistical and analytical visualizations where the focus is on data analysis rather than interactivity. Use Python visuals when you need:
- Statistical charts (distributions, regressions, correlations, violin plots)
- Analytical visualizations leveraging scipy, scikit-learn, or statsmodels
- Chart types that seaborn/matplotlib handle well but Power BI natives don't support
Output is static PNG -- no cross-filtering FROM the visual, no hover/tooltip interactivity. Use Deneb instead for interactive custom visuals. Use SVG measures for simple inline graphics in tables/cards.
References
references/community-examples.md-- seaborn gallery examples organized by chart type, plus matplotlib and Python Graph Gallery linksreferences/chart-patterns.md-- Common matplotlib/seaborn chart patterns (bar, heatmap, donut, KPI, area)examples/script/-- Standalone Python scripts (bar-chart, trend-line) -- ready to inject into visual.json after escapingexamples/visual/bar-chart.json-- PBIR visual.json: horizontal stacked bar with PY comparison lines and % change labelsexamples/visual/kpi-card.json-- PBIR visual.json: text-based KPI with value, % change indicator, and PY comparisonexamples/visual/trend-line.json-- PBIR visual.json: area chart with line plot and monthly x-axis
Fetching Docs
To retrieve current Python visual / package support docs, use microsoft_docs_search + microsoft_docs_fetch (MCP) if available, otherwise mslearn search + mslearn fetch (CLI). Search based on the user's request and run multiple searches as needed to ensure sufficient context before proceeding.
Related Skills
pbi-report-design-- Layout and design best practicesr-visuals-- R Script visuals (same concept, different language)deneb-visuals-- Vega/Vega-Lite visuals (interactive, vector-based alternative)svg-visuals-- SVG via DAX measures (lightweight inline graphics)pbir-format(pbip plugin) -- PBIR JSON format reference
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

