matplotlib-data-visualization
Chart design and data storytelling guidelines for matplotlib. Use when creating visualizations that need to communicate a clear message, tell a story with data, or follow best practices for readability and design. Focuses on visualization principles rather than matplotlib API syntax.
pavelzw · 已有静态检查记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add pavelzw/skill-forge --skill matplotlib-data-visualization技能说明
name: matplotlib-data-visualization description: >- Chart design and data storytelling guidelines for matplotlib. Use when creating visualizations that need to communicate a clear message, tell a story with data, or follow best practices for readability and design. Focuses on visualization principles rather than matplotlib API syntax. license: BSD-3-Clause
Storytelling with Data: Chart Design Guidelines for Matplotlib
This skill focuses on visualization design principles for creating clear, compelling charts that communicate your data's message. It is not a matplotlib API reference — it is a guide for making charts that are easy to read, honest, and visually appealing.
Choose the Right Chart Type
Avoid pie charts for most use cases. Human perception is poor at comparing angles and areas. Use horizontal bar charts instead — they are the easiest chart type to read for categorical comparisons.
Avoid grouped bar charts. Side-by-side bars are hard to compare across groups. Use stacked bar charts if the message is about part-to-whole composition, or a slope chart if the message is about the change between two groups or time periods.
Use horizontal bar charts for categorical comparisons. They allow natural left-to-right reading and accommodate long category labels without rotation.
import matplotlib.pyplot as plt
categories = ["Customer Support", "Engineering", "Marketing", "Sales", "Operations"]
values = [82, 95, 67, 78, 71]
fig, ax = plt.subplots(figsize=(8, 4))
bars = ax.barh(categories, values, color="#cccccc")
# Highlight the key bar
bars[1].set_color("#e63946")
ax.set_xlim(0, 110)
ax.set_title("Engineering leads in satisfaction scores", loc="left", fontweight="bold")
ax.spines[["top", "right", "bottom"]].set_visible(False)
ax.tick_params(left=False)
ax.xaxis.set_visible(False)
# Label bars directly instead of using an x-axis
for bar, val in zip(bars, values):
ax.text(bar.get_width() + 1.5, bar.get_y() + bar.get_height() / 2,
str(val), va="center", fontsize=10)
plt.tight_layout()
Use vertical bar charts when the x-axis represents chronological progression. Time reads naturally left-to-right on a horizontal axis.
Use line charts to show continuous data over time. Lines clearly convey trends, rates of change, and patterns. Use them instead of bar charts when the focus is on the shape of change rather than individual values.
Use slope charts to compare exactly two time periods or categories, emphasizing the direction and magnitude of change between them.
fig, ax = plt.subplots(figsize=(4, 5))
# Two time periods
labels = ["2022", "2024"]
product_a = [45, 62]
product_b = [60, 55]
ax.plot([0, 1], product_a, "o-", color="#e63946", linewidth=2, markersize=8)
ax.plot([0, 1], product_b, "o-", color="#aaaaaa", linewidth=2, markersize=8)
# Label lines directly at their endpoints
ax.text(-0.15, product_a[0], f"Product A: {product_a[0]}", va="center", color="#e63946")
ax.text(1.08, product_a[1], f"{product_a[1]}", va="center", color="#e63946", fontweight="bold")
ax.text(-0.15, product_b[0], f"Product B: {product_b[0]}", va="center", color="#aaaaaa")
ax.text(1.08, product_b[1], f"{product_b[1]}", va="center", color="#aaaaaa")
ax.set_xticks([0, 1])
ax.set_xticklabels(labels)
ax.set_xlim(-0.4, 1.4)
ax.spines[["top", "right", "left", "bottom"]].set_visible(False)
ax.yaxis.set_visible(False)
ax.set_title("Product A overtook Product B", loc="left", fontweight="bold")
plt.tight_layout()
Reduce Clutter
Every non-data element competes for attention. Remove anything that does not directly help the reader understand the data.
Always despine at least the top and right spines — they form a box around the data that adds no information. For charts where you label data directly (e.g., bar values on top of bars), you can also remove the left spine and y-axis entirely, leaving only the data and its labels.
# Minimum: always remove top and right
ax.spines[["top", "right"]].set_visible(False)
# When bars are labeled directly, also remove left spine and y-axis
ax.spines[["top", "right", "left"]].set_visible(False)
ax.yaxis.set_visible(False)
# Full despine for slope charts or minimal designs
ax.spines[["top", "right", "left", "bottom"]].set_visible(False)
Remove gridlines. If gridlines are necessary, use a light grey (#eeeeee or #dddddd).
ax.yaxis.grid(True, color="#eeeeee", linewidth=0.8)
ax.set_axisbelow(True)
Remove legends — label data directly. Legends force the reader to look back and forth between the chart and the legend. Place labels next to the data they describe.
fig, ax = plt.subplots(figsize=(8, 4))
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
online = [120, 135, 150, 145, 170, 190]
retail = [200, 190, 180, 175, 165, 155]
ax.plot(months, online, color="#e63946", linewidth=2.5)
ax.plot(months, retail, color="#aaaaaa", linewidth=2.5)
# Label lines directly at the last data point
ax.text(len(months) - 0.85, online[-1] + 4, "Online", color="#e63946",
fontweight="bold", fontsize=11)
ax.text(len(months) - 0.85, retail[-1] + 4, "Retail", color="#aaaaaa",
fontweight="bold", fontsize=11)
ax.spines[["top", "right"]].set_visible(False)
ax.set_title("Online sales surpassing retail", loc="left", fontweight="bold")
plt.tight_layout()
Label bars directly instead of relying on axis tick marks. This eliminates the need for gridlines entirely.
fig, ax = plt.subplots(figsize=(8, 3.5))
categories = ["Q1", "Q2", "Q3", "Q4"]
values = [24, 31, 28, 42]
bars = ax.bar(categories, values, color="#cccccc", width=0.5)
bars[-1].set_color("#e63946") # Highlight Q4
# Place value labels on top of each bar
for bar, val in zip(bars, values):
ax.text(bar.get_x() + bar.get_width() / 2, bar.get_height() + 0.8,
str(val), ha="center", va="bottom", fontsize=11)
ax.spines[["top", "right", "left"]].set_
阅读完整来源 ↗