Data Visualization Script AI Prompts for Data Scientists
TL;DR
- AI prompts accelerate Matplotlib and Seaborn script generation for common visualization tasks
- Structured prompts produce cleaner, more maintainable visualization code
- Prompt templates reduce iteration cycles when refining charts
- Customization prompts handle specific branding and publication requirements
- Best practice prompts help learn advanced visualization techniques
Introduction
Data visualization is the bridge between analytical work and decision-maker comprehension. Yet the “last mile” of data science—transforming analysis into clear, compelling visuals—often consumes disproportionate time. Writing and refining Matplotlib code to achieve publication-quality output is tedious, and the gap between functional and excellent visualizations frequently remains unfilled.
The challenge is that visualization requirements are highly specific: a chart that works for exploratory analysis rarely meets presentation standards without significant rework. Customizing fonts, colors, layout, and annotations requires deep library knowledge that takes years to develop.
AI changes the visualization coding workflow. When structured prompts guide code generation, data scientists can rapidly produce visualization scripts that meet specific requirements, then refine them with targeted follow-up prompts.
This guide provides AI prompts designed specifically for data scientists who want to accelerate Matplotlib and Seaborn visualization development. These prompts address common chart types, customization workflows, styling best practices, and advanced techniques.
Table of Contents
- Matplotlib Fundamentals
- Common Chart Types
- Seaborn Integration
- Styling and Theming
- Customization Workflows
- Publication-Ready Output
- Advanced Visualizations
- Efficiency and Automation
- FAQ: Data Visualization Script Excellence
- Conclusion
Matplotlib Fundamentals
Figure and Axes Structure
Understanding the Matplotlib object hierarchy is essential for programmatic control.
Prompt for Figure Setup:
Generate Matplotlib figure setup code for [CHART TYPE/DESCRIPTION]:
Requirements:
- Figure size: [WIDTH x HEIGHT in inches]
- Resolution: [DPI]
- Number of subplots: [ROWS x COLUMNS]
- Subplot spacing: [ADJUSTMENTS IF NEEDED]
- Background color: [COLOR IF NOT DEFAULT]
Object naming convention: [STANDARD/BRIEF/DESCRIPTIVE]
Export format: [PNG/PDF/SVG]
Include:
- plt.figure() or plt.subplots() as appropriate
- Proper figure object assignment
- Axes object extraction for multi-panel
- High-resolution export setup
Generate production-ready figure setup code.
Axes Customization
Axes control the data domain and display characteristics.
Prompt for Axes Configuration:
Configure axes for [CHART TYPE/DESCRIPTION]:
Axes requirements:
1. **Axis limits**:
- X-axis range: [MIN, MAX]
- Y-axis range: [MIN, MAX]
- Z-axis if 3D: [RANGE]
- Manual or automatic based on data
2. **Axis scaling**:
- Linear (default)
- Logarithmic
- Symlog
- Custom scale
3. **Tick formatting**:
- Major tick locations
- Minor tick configuration
- Label format (currency, percentage, scientific)
- Tick label rotation
4. **Axis labels and titles**:
- X-axis label with units
- Y-axis label with units
- Subplot titles if applicable
- Title positioning
5. **Gridlines**:
- Major grid vs. minor grid
- Grid styling (color, linestyle, alpha)
- Which axes get grids
Generate axes configuration code with proper Matplotlib syntax.
Common Chart Types
Line Charts
Line charts show trends and changes over continuous variables.
Prompt for Line Chart:
Generate Matplotlib line chart for [DATA/DESCRIPTION]:
Data specifications:
- X values: [DATA SOURCE OR DESCRIPTION]
- Y values: [DATA SOURCE OR DESCRIPTION]
- Multiple lines: [YES/NO AND HOW MANY]
- Data points markers: [YES/NO/MARKER STYLE]
Visual customization:
- Line colors: [COLORS OR PALETTE]
- Line styles: [SOLID/DASHED/DOTTED]
- Line widths: [WIDTH VALUES]
- Marker sizes: [SIZE VALUES]
Annotations needed:
- Data labels: [YES/NO/SELECTED POINTS]
- Annotations: [ANY SPECIFIC LABELS]
- Reference lines: [HORIZONTAL/VERTICAL]
Legend requirements:
- Position: [BEST/UPPER RIGHT/ETC.]
- Style: [HORIZONTAL/VERTICAL]
- Include values: [YES/NO]
Generate complete line chart code with sample data structure.
Bar Charts
Bar charts compare discrete categories or show frequency distributions.
Prompt for Bar Chart:
Generate Matplotlib bar chart for [DATA/DESCRIPTION]:
Chart specifications:
- Bar orientation: [VERTICAL/HORIZONTAL]
- Bar type: [REGULAR/GROUPED/STACKED]
- Categories: [LIST OR DATA SOURCE]
- Values: [DATA SOURCE]
- Number of series: [1/2/3/MORE]
Visual styling:
- Bar colors: [COLORS OR PALETTE]
- Edge color: [COLOR]
- Edge width: [WIDTH]
- Bar width: [WIDTH IF CUSTOM]
Value display:
- Show values on bars: [YES/NO]
- Value label position: [INSIDE/OUTSIDE]
- Number format: [INTEGER/DECIMAL/PERCENTAGE]
Comparison features:
- Reference line: [VALUE OR NONE]
- Baseline comparison: [YES/NO]
Generate bar chart code with proper category handling.
Scatter Plots
Scatter plots reveal relationships between variables and identify clusters.
Prompt for Scatter Plot:
Generate Matplotlib scatter plot for [DATA/DESCRIPTION]:
Data specifications:
- X variable: [DATA SOURCE]
- Y variable: [DATA SOURCE]
- Size variable: [OPTIONAL - FOR BUBBLE]
- Color variable: [OPTIONAL - FOR COLOR MAPPING]
- Category variable: [OPTIONAL - FOR MARKER TYPES]
Visual customization:
- Marker type: [CIRCLE/SQUARE/TRIANGLE/ETC.]
- Marker size: [SIZE VALUE OR VARIABLE]
- Marker color: [SINGLE COLOR OR MAPPING]
- Marker alpha: [OPACITY 0-1]
Color mapping if applicable:
- Colormap: [VIRIDIS/PLASMA/ETC.]
- Colorbar: [YES/NO]
- Color range: [MIN/MAX]
- Normalization: [LINEAR/LOG]
Trend visualization:
- Regression line: [YES/NO]
- Confidence interval: [YES/NO/LEVEL]
Generate scatter plot code with optional trend analysis.
Histograms
Histograms show distributions and frequency patterns.
Prompt for Histogram:
Generate Matplotlib histogram for [DATA/DESCRIPTION]:
Distribution requirements:
- Data values: [ARRAY OR SERIES]
- Number of bins: [AUTO/SPECIFIC NUMBER]
- Bin edges: [ARRAY IF CUSTOM]
- Normalization: [COUNT/DENSITY/PROBABILITY]
Visual styling:
- Bar color: [COLOR]
- Edge color: [COLOR]
- Edge width: [WIDTH]
- Transparency: [ALPHA VALUE]
Statistical overlays:
- Mean line: [YES/NO]
- Median line: [YES/NO]
- Standard deviation bands: [YES/NO]
- Kernel density estimate: [YES/NO]
Multiple distributions if applicable:
- Side-by-side: [YES/NO]
- Stacked: [YES/NO]
- Overlaid with transparency: [YES/NO]
Generate histogram code with optional statistical annotations.
Seaborn Integration
Seaborn Figure-Level vs. Axes-Level
Understanding Seaborn’s dual interface guides appropriate usage.
Prompt for Seaborn Interface Selection:
Explain and implement [SEABORN CHART TYPE] for [DATA/DESCRIPTION]:
Interface options:
1. **Axes-level functions** (sns.barplot, sns.lineplot, etc.):
- Returns matplotlib Axes object
- Fine-grained control over axes
- Multiple plots on same figure
- Manual subplot management
2. **Figure-level functions** (sns.catplot, sns.relplot, etc.):
- Returns Seaborn FacetGrid or JointGrid
- Automatic handling of row/col facets
- Built-in legend management
- Less manual control
Selection criteria:
- Number of subplots needed
- Level of customization required
- Faceting requirements
- Integration with existing matplotlib code
For your use case:
- Recommended approach
- Code implementation
- How to customize further
Generate Seaborn implementation with interface guidance.
Seaborn Statistical Visualization
Seaborn excels at statistical plots with built-in confidence intervals.
Prompt for Seaborn Statistical Plot:
Generate Seaborn statistical plot for [ANALYSIS/DESCRIPTION]:
Statistical requirements:
- Primary relationship: [X VS Y, DISTRIBUTION, ETC.]
- Aggregation method: [MEAN/MEDIAN/SUM/COUNT]
- Confidence interval: [95%/90%/NONE]
- Bootstrap iterations: [NUMBER IF CUSTOM]
Visual customization:
- Style parameter: [CATEGORY FOR LINE STYLING]
- Hue parameter: [CATEGORY FOR COLOR]
- Size parameter: [VARIABLE FOR MARKER SIZE]
- Markers: [YES/NO/MARKER TYPE]
Facet requirements:
- Row faceting: [CATEGORY]
- Column faceting: [CATEGORY]
- Facet wrapping: [NUMBER]
Additional layers:
-sns.lineplot() with ci
- sns.regplot() for regression
- sns.residplot() for residuals
Generate statistical visualization with proper Seaborn syntax.
Styling and Theming
Matplotlib Style Sheets
Style sheets provide consistent theming across all charts.
Prompt for Matplotlib Style:
Apply Matplotlib style sheet for [CONTEXT/PUBLICATION TYPE]:
Style options:
1. **Built-in styles**:
- ggplot (R-inspired)
- seaborn-v0_8 (Seaborn default)
- presentation (high contrast)
- dark_background
2. **Publication contexts**:
- Journal figure (clean, minimal)
- Presentation (bold, high contrast)
- Web/Dashboard (readable, balanced)
- Internal analysis (functional)
3. **Custom style elements**:
- Font family and sizes
- Line widths and styles
- Color palette
- Grid styles
- Spines and ticks
To apply:
```python
plt.style.use('style_name')
# or for temporary use
with plt.style.context('style_name'):
# plotting code
Generate style application code with customization options.
### Custom Theme Creation
Create branded themes for consistent organization-wide visualization.
**Prompt for Custom Theme Creation:**
Create custom Matplotlib theme for [ORGANIZATION/BRAND]:
Theme components:
-
Colors:
- Primary: [BRAND PRIMARY]
- Secondary: [BRAND SECONDARY]
- Accent: [BRAND ACCENT]
- Background: [LIGHT/DARK]
- Text: [PRIMARY TEXT COLOR]
-
Typography:
- Font family: [PRIMARY FONT]
- Title size: [SIZE]
- Label size: [SIZE]
- Tick label size: [SIZE]
- Legend font size: [SIZE]
-
Grid and spines:
- Grid color: [COLOR]
- Grid alpha: [OPACITY]
- Spine visibility: [TOP/RIGHT/HIDE]
- Spine color: [COLOR]
-
Line and marker defaults:
- Line width default: [WIDTH]
- Marker size default: [SIZE]
- Error bar cap size: [SIZE]
Implementation:
# As style sheet file
# As rcParams in code
# As context manager
Generate theme file and implementation code.
## Customization Workflows
### Color Management
Manage color consistently across visualizations.
**Prompt for Color Management:**
Implement color management for [VISUALIZATION PROJECT]:
Color approaches:
-
Named colors:
- Seaborn deep/pastel/bright/muted palettes
- Matplotlib named colors
- CSS named colors
-
Hex/RGB colors:
- Direct hex specification
- RGB tuple format
- Normalized 0-1 RGB
-
Colormaps:
- Sequential: viridis, plasma, inferno
- Diverging: coolwarm, RdBu
- Cyclical: hsv, twilight
-
Palette objects:
- sns.color_palette()
- sns.cubehelix_palette()
- sns.dark_palette()
For your visualization:
- Color approach recommended
- Specific color values
- Palette generation code
Generate color implementation with helper functions.
### Annotation and Text
Annotations transform raw charts into insight-communicating tools.
**Prompt for Annotation Implementation:**
Add annotations to [CHART/DESCRIPTION]:
Annotation types:
-
Direct labels:
- Value labels on bars/points
- Position: [AUTO/SPECIFIC]
- Format: [NUMBER/DURATION/PERCENTAGE]
- Font: [SIZE/WEIGHT]
-
Callout annotations:
- Arrow or line pointing to feature
- Text box with explanation
- Box styling: [FILL/EDGE/ALPHA]
-
Statistical annotations:
- Significance brackets
- Test results (p-values)
- Confidence intervals
- Sample size notation
-
Reference annotations:
- Vertical/horizontal lines
- Shaded regions (e.g., significance)
- Target or goal lines
-
Text styling:
- Font family
- Size and weight
- Color matching
- Alignment
Matplotlib annotation functions:
- ax.text() for direct text
- ax.annotate() for pointed annotations
- ax.axhline/axvline for lines
- ax.fill_between for regions
Generate annotation code for your specific chart.
## Publication-Ready Output
### Figure Sizing for Journals
Journal figures have specific size and resolution requirements.
**Prompt for Journal Figure Sizing:**
Generate publication-ready figure for [JOURNAL/TARGET]:
Journal requirements:
-
Size constraints:
- Single column: [WIDTH in inches]
- Double column: [WIDTH in inches]
- Maximum height: [HEIGHT in inches]
- Aspect ratio constraints
-
Resolution:
- Bitmap (PNG/TIFF): [DPI, typically 300+]
- Vector (EPS/PDF/SVG): for line art
- Minimum resolution for photographs
-
Color mode:
- RGB for color figures
- CMYK often required for print
- Grayscale compatibility
-
File format:
- Journal-specific requirements
- Combined with supplementary
- Source file vs. final file
Code implementation:
# Journal-specific sizing
fig = plt.figure(figsize=(width, height))
# High-resolution export
fig.savefig('filename.tiff', dpi=300, format='tiff')
# Vector format for line art
fig.savefig('filename.pdf', format='pdf')
Generate journal-ready figure code with proper sizing.
### Multi-Panel Figure Layout
Complex figures often require organized multi-panel layouts.
**Prompt for Multi-Panel Layout:**
Generate multi-panel figure layout for [ANALYSIS/DESCRIPTION]:
Layout requirements:
- Number of panels: [ROWS x COLUMNS]
- Total figure size: [WIDTH x HEIGHT]
- Panel arrangement: [GRID/IRREGULAR]
Panel specifications:
- [PANEL A]: [CHART TYPE], spans [ROWS x COLS]
- [PANEL B]: [CHART TYPE], spans [ROWS x COLS]
- [PANEL C]: [CHART TYPE], spans [ROWS x COLS]
- [PANEL D]: [CHART TYPE], spans [ROWS x COLS]
Spacing adjustments:
- Subplot spacing: [WSPACE, HSPACE]
- Figure margins: [LEFT/RIGHT/TOP/BOTTOM]
- Panel labels: [A)/B)/C) OR A/B/C]
Shared axes if applicable:
- Shared X-axis: [YES/NO AND WHICH]
- Shared Y-axis: [YES/NO AND WHICH]
Panel arrangement code:
fig = plt.figure(figsize=(width, height))
gs = fig.add_gridspec(rows, cols, wspace=space, hspace=space)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[0, 1:])
Generate multi-panel figure code with proper layout.
## Advanced Visualizations
### 3D Plotting
3D visualization for multi-dimensional data exploration.
**Prompt for 3D Plot:**
Generate 3D plot for [DATA/DESCRIPTION]:
3D plot type:
- Scatter plot: mplot3d Axes3D.scatter()
- Line plot: plot() with 3D projection
- Surface plot: plot_surface()
- Wireframe: plot_wireframe()
- Bar plot: bar3d()
Data specifications:
- X, Y, Z coordinates: [DATA SOURCES]
- Fourth dimension (color/size): [IF APPLICABLE]
Viewing angle:
- Azimuth angle (rotation): [DEGREES]
- Elevation angle (tilt): [DEGREES]
- Or use: ax.view_init(elev=, azim=)
Surface coloring:
- Colormap: [VIRIDIS/PLASMA/ETC.]
- Colorbar: [YES/NO]
- Shading: [FLAT/SONNT]
Annotations:
- Axis labels
- Title
- Optional text labels on points
Generate 3D visualization code with proper projection setup.
### Animated Visualizations
Animations for showing temporal changes or data evolution.
**Prompt for Animation:**
Generate animated visualization for [DATA/DESCRIPTION]:
Animation type:
- Line animation (growing line)
- Scatter animation (moving points)
- Bar animation (changing values)
- Image sequence
Frame structure:
- Number of frames: [N]
- Data update method: [SLICING/APPEND/UPDATE]
- Interpolation if applicable
Animation controls:
- Play/pause button
- Speed control
- Frame slider
- Direction toggle
Export options:
- GIF: [YES/NO AND FPS]
- MP4: [YES/NO AND CODEC]
- HTML: [YES/NO FOR INTERACTIVE]
Implementation approaches:
- matplotlib.animation.FuncAnimation
- ArtistAnimation for pre-computed frames
- HTML5 animation for web
Memory considerations:
- Frame limit for long animations
- Blitting for performance
- Clear figure vs. update
Generate animation code with chosen implementation approach.
## Efficiency and Automation
### Visualization Functions
Create reusable visualization functions to accelerate repetitive tasks.
**Prompt for Visualization Function:**
Create reusable visualization function for [CHART TYPE]:
Function specifications:
- Function name: [DESCRIPTIVE NAME]
- Input parameters: [DATA + OPTIONS]
- Return value: [AXES OBJECT OR FIGURE]
- Default behaviors: [STANDARD OPTIONS]
Parameter structure:
def plot_[chart_type](
data,
x=None,
y=None,
hue=None,
color=None,
title=None,
xlabel=None,
ylabel=None,
figsize=None,
style=None,
**kwargs
):
# Implementation
return ax
Reusability features:
- Sensible defaults
- Keyword argument passthrough
- Consistent return types
- Docstring documentation
Style integration:
- Use organization theme
- Match publication style
- Include in style sheet
Generate production-ready visualization function.
### Batch Visualization
Automate visualization generation for multiple variables or groups.
**Prompt for Batch Visualization:**
Generate batch visualization code for [ANALYSIS/CONTEXT]:
Batch requirements:
- Variables to visualize: [LIST OR PATTERN]
- Grouping variable: [CATEGORY FOR SUBPLOTS]
- Output format: [ONE FILE/MULTIPLE FILES/GRID]
Approaches:
- Subplot grid (one figure, all vars):
fig, axes = plt.subplots(rows, cols)
for i, var in enumerate(variables):
plot_on_axis(axes.flat[i], var)
- Multi-figure loop (multiple files):
for var in variables:
fig, ax = plt.subplots()
plot_single(fig, ax, var)
fig.savefig(f'{var}.png')
- Faceted data (Seaborn FacetGrid):
g = sns.FacetGrid(data, col='group_var')
g.map(plot_func, 'x', 'y')
Output organization:
- File naming convention
- Folder structure
- Metadata/watermarks if needed
- Index/overview figure
Generate batch visualization code for your workflow.
## FAQ: Data Visualization Script Excellence
### How do I make Matplotlib charts match Seaborn aesthetics?
Apply a Seaborn style before creating Matplotlib objects, or manually set rcParams to Seaborn values. Seaborn internally sets matplotlib rcParams to achieve its aesthetics, so `sns.set()` before your plotting code applies those settings. For Seaborn's specific font and theme, use `sns.set_context()` with desired context (paper, notebook, talk, poster).
### Why does my exported figure have extra whitespace?
Matplotlib adds whitespace around the axes by default. Control this with `fig.tight_layout()` before save, or manually set `fig.subplots_adjust()` with specific margins. For precise control, use `bbox_inches='tight'` with `plt.savefig()` which auto-crops, or specify `bbox_inches` with explicit inches.
### How do I overlay a histogram with a density curve?
Use `sns.histplot()` with `kde=True` for Seaborn, or manually overlay using `ax.hist()` for data and `sns.kdeplot()` or scipy's `gaussian_kde` for the density curve. Ensure the density is normalized appropriately (set `density=True` in hist) so the histogram and KDE share the same y-axis scale.
### How can I create publication-quality legends?
Use `ax.legend()` with specific parameters: `loc` for position, `frameon` for box styling, `fontsize` for size, `markerscale` for marker size in legend vs. plot. For custom legends with multiple columns, use `ncol` parameter. Remove redundant legend entries by labeling only once and using handles.
### How do I handle Chinese/Japanese/Korean characters in matplotlib?
Matplotlib supports Unicode by default in modern versions. Ensure you use a font that includes CJK glyphs by setting `plt.rcParams['font.sans-serif']` to a font like Noto Sans CJK or SimHei, and set `plt.rcParams['axes.unicode_minus'] = False` to prevent minus sign issues.
## Conclusion
Data visualization coding with Matplotlib and Seaborn doesn't have to be a tedious, iterative struggle. The AI prompts in this guide accelerate script generation, reduce customization cycles, and help data scientists produce publication-quality visualizations more efficiently.
The key takeaways from this guide are:
1. **Structure prompts for reproducibility** - Include data specs, visualization type, and customization needs in every prompt.
2. **Use Seaborn for statistical plots** - Built-in confidence intervals and statistical estimation save significant code.
3. **Style early, not late** - Apply themes and styling at the start to avoid rework.
4. **Functions accelerate repetitive work** - Invest time creating reusable visualization functions for common chart types.
5. **Test exports at target resolution** - Journal and presentation requirements differ; verify early.
Your next step is to identify your three most common visualization types and create template prompts for each. AI Unpacker provides the framework; your scientific visualization expertise provides the insight.