create-viz

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/create-viz - Create Visualizations

/create-viz - 创建数据可视化

If you see unfamiliar placeholders or need to check which tools are connected, see CONNECTORS.md.
Create publication-quality data visualizations using Python. Generates charts from data with best practices for clarity, accuracy, and design.
若遇到不熟悉的占位符或需要查看已连接的工具,请参考 CONNECTORS.md
使用Python创建出版级质量的数据可视化。遵循清晰度、准确性和设计最佳实践,基于数据生成图表。

Usage

使用方法

/create-viz <data source> [chart type] [additional instructions]
/create-viz <数据源> [图表类型] [额外说明]

Workflow

工作流程

1. Understand the Request

1. 理解需求

Determine:
  • Data source: Query results, pasted data, CSV/Excel file, or data to be queried
  • Chart type: Explicitly requested or needs to be recommended
  • Purpose: Exploration, presentation, report, dashboard component
  • Audience: Technical team, executives, external stakeholders
确定以下信息:
  • 数据源:查询结果、粘贴的数据、CSV/Excel文件,或需要查询的数据
  • 图表类型:用户明确指定的类型,或需要推荐的类型
  • 用途:探索性分析、演示、报告、仪表盘组件
  • 受众:技术团队、管理层、外部利益相关者

2. Get the Data

2. 获取数据

If data warehouse is connected and data needs querying:
  1. Write and execute the query
  2. Load results into a pandas DataFrame
If data is pasted or uploaded:
  1. Parse the data into a pandas DataFrame
  2. Clean and prepare as needed (type conversions, null handling)
If data is from a previous analysis in the conversation:
  1. Reference the existing data
若已连接数据仓库且需要查询数据:
  1. 编写并执行查询语句
  2. 将结果加载至pandas DataFrame
若数据为粘贴或上传:
  1. 将数据解析为pandas DataFrame
  2. 根据需要进行清洗和预处理(类型转换、空值处理等)
若数据来自对话中之前的分析:
  1. 引用已有的数据

3. Select Chart Type

3. 选择图表类型

If the user didn't specify a chart type, recommend one based on the data and question:
Data RelationshipRecommended Chart
Trend over timeLine chart
Comparison across categoriesBar chart (horizontal if many categories)
Part-to-whole compositionStacked bar or area chart (avoid pie charts unless <6 categories)
Distribution of valuesHistogram or box plot
Correlation between two variablesScatter plot
Two-variable comparison over timeDual-axis line or grouped bar
Geographic dataChoropleth map
RankingHorizontal bar chart
Flow or processSankey diagram
Matrix of relationshipsHeatmap
Explain the recommendation briefly if the user didn't specify.
若用户未指定图表类型,需根据数据和需求推荐合适的类型:
数据关系推荐图表
随时间变化的趋势折线图
跨类别对比柱状图(类别较多时使用横向柱状图)
整体与部分的构成堆叠柱状图或面积图(除非类别少于6个,否则避免使用饼图)
数值分布直方图或箱线图
两个变量的相关性散点图
双变量随时间的对比双轴折线图或分组柱状图
地理数据分级统计图
排名排序横向柱状图
流程或流向桑基图
关系矩阵热力图
若用户未指定类型,需简要说明推荐理由。

4. Generate the Visualization

4. 生成可视化图表

Write Python code using one of these libraries based on the need:
  • matplotlib + seaborn: Best for static, publication-quality charts. Default choice.
  • plotly: Best for interactive charts or when the user requests interactivity.
Code requirements:
python
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
根据需求使用以下库编写Python代码:
  • matplotlib + seaborn:最适合创建静态、出版级质量的图表,为默认选择。
  • plotly:最适合创建交互式图表,或用户明确要求交互性时使用。
代码要求:
python
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd

Set professional style

设置专业样式

plt.style.use('seaborn-v0_8-whitegrid') sns.set_palette("husl")
plt.style.use('seaborn-v0_8-whitegrid') sns.set_palette("husl")

Create figure with appropriate size

创建合适尺寸的画布

fig, ax = plt.subplots(figsize=(10, 6))
fig, ax = plt.subplots(figsize=(10, 6))

[chart-specific code]

[图表专属代码]

Always include:

必须包含以下内容:

ax.set_title('Clear, Descriptive Title', fontsize=14, fontweight='bold') ax.set_xlabel('X-Axis Label', fontsize=11) ax.set_ylabel('Y-Axis Label', fontsize=11)
ax.set_title('清晰、描述性的标题', fontsize=14, fontweight='bold') ax.set_xlabel('X轴标签', fontsize=11) ax.set_ylabel('Y轴标签', fontsize=11)

Format numbers appropriately

合理格式化数值

- Percentages: '45.2%' not '0.452'

- 百分比:显示为'45.2%'而非'0.452'

- Currency: '$1.2M' not '1200000'

- 货币:显示为'$1.2M'而非'1200000'

- Large numbers: '2.3K' or '1.5M' not '2300' or '1500000'

- 大数值:显示为'2.3K'或'1.5M'而非'2300'或'1500000'

Remove chart junk

移除冗余图表元素

ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False)
plt.tight_layout() plt.savefig('chart_name.png', dpi=150, bbox_inches='tight') plt.show()
undefined
ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False)
plt.tight_layout() plt.savefig('chart_name.png', dpi=150, bbox_inches='tight') plt.show()
undefined

5. Apply Design Best Practices

5. 应用设计最佳实践

Color:
  • Use a consistent, colorblind-friendly palette
  • Use color meaningfully (not decoratively)
  • Highlight the key data point or trend with a contrasting color
  • Grey out less important reference data
Typography:
  • Descriptive title that states the insight, not just the metric (e.g., "Revenue grew 23% YoY" not "Revenue by Month")
  • Readable axis labels (not rotated 90 degrees if avoidable)
  • Data labels on key points when they add clarity
Layout:
  • Appropriate whitespace and margins
  • Legend placement that doesn't obscure data
  • Sorted categories by value (not alphabetically) unless there's a natural order
Accuracy:
  • Y-axis starts at zero for bar charts
  • No misleading axis breaks without clear notation
  • Consistent scales when comparing panels
  • Appropriate precision (don't show 10 decimal places)
色彩:
  • 使用一致、适合色盲人群的配色方案
  • 有意义地使用色彩(而非装饰性)
  • 用对比色突出关键数据点或趋势
  • 将次要参考数据设为灰色
排版:
  • 标题需描述洞察,而非仅说明指标(例如:"营收同比增长23%"而非"月度营收")
  • 轴标签易读(尽可能避免90度旋转)
  • 在关键数据点添加数据标签以提升清晰度
布局:
  • 合理的留白和边距
  • 图例放置在不遮挡数据的位置
  • 类别按数值排序(而非字母顺序),除非存在自然顺序
准确性:
  • 柱状图的Y轴从0开始
  • 除非有明确标注,否则不使用误导性的轴中断
  • 对比面板时使用一致的刻度
  • 合理的精度(避免显示10位小数)

6. Save and Present

6. 保存与展示

  1. Save the chart as a PNG file with descriptive name
  2. Display the chart to the user
  3. Provide the code used so they can modify it
  4. Suggest variations (different chart type, different grouping, zoomed time range)
  1. 将图表保存为PNG文件,文件名需具有描述性
  2. 向用户展示图表
  3. 提供所用代码,方便用户修改
  4. 建议变体(不同图表类型、不同分组方式、缩放时间范围等)

Examples

示例

/create-viz Show monthly revenue for the last 12 months as a line chart with the trend highlighted
/create-viz Here's our NPS data by product: [pastes data]. Create a horizontal bar chart ranking products by score.
/create-viz Query the orders table and create a heatmap of order volume by day-of-week and hour
/create-viz 展示过去12个月的月度营收,用折线图呈现并突出趋势
/create-viz 这是我们按产品划分的NPS数据:[粘贴数据]。创建横向柱状图,按得分对产品进行排名。
/create-viz 查询订单表,创建按星期几和小时分布的订单量热力图

Tips

提示

  • If you want interactive charts (hover, zoom, filter), mention "interactive" and Claude will use plotly
  • Specify "presentation" if you need larger fonts and higher contrast
  • You can request multiple charts at once (e.g., "create a 2x2 grid of charts showing...")
  • Charts are saved to your current directory as PNG files
  • 若需要交互式图表(悬停、缩放、筛选),请提及"interactive",Claude将使用plotly
  • 若用于演示,可指定"presentation",将生成更大字体和更高对比度的图表
  • 可同时请求多个图表(例如:"创建2x2网格图表,展示...")
  • 图表将保存为PNG文件至当前目录