data-visualization について
探索的データ分析、統計プロット、インタラクティブなチャート、ダッシュボードの例と指針を提供するデータ可視化スキルです。Pythonのデータを扱い、パターンを視覚的に伝える用途に向いています。
主な機能
- 01Matplotlibでプロットを作成
- 02Seabornで統計プロットを作成
- 03集計チェックでデータを探索
- 04Plotlyでインタラクティブなチャートを作成
- 05Plotly Dashでダッシュボードを作成
- 06PNG、PDF、SVG形式で出力
活用シーン
- 01データセットの分布や関係を調べる
- 02時系列やカテゴリの比較を示す
- 03インタラクティブなデータダッシュボードを構築
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ pluginagentmarketplace/ custom-plugin-ai-data-scientist --skill data-visualizationインストール後、Claude Code で/data-visualizationを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
assets/chart_styles.yamlreferences/CHART_SELECTION_GUIDE.mdscripts/quick_plot.py詳細
データ可視化
データの洞察を探り、伝えるための魅力的な可視化を作成します。
クイックスタート
Matplotlib の基本
import matplotlib.pyplot as plt
# Line plot
plt.figure(figsize=(10, 6))
plt.plot(x, y, marker='o', linestyle='-', color='blue', label='Series 1')
plt.xlabel('X Label')
plt.ylabel('Y Label')
plt.title('Title')
plt.legend()
plt.grid(True, alpha=0.3)
plt.show()
# Bar chart
plt.bar(categories, values, color='skyblue', edgecolor='black')
plt.xlabel('Categories')
plt.ylabel('Values')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
統計プロットのための Seaborn
import seaborn as sns
# Set style
sns.set_style("whitegrid")
# Distribution
sns.histplot(data=df, x='value', kde=True, bins=30)
# Box plot
sns.boxplot(data=df, x='category', y='value')
# Violin plot
sns.violinplot(data=df, x='category', y='value')
# Heatmap
corr = df.corr()
sns.heatmap(corr, annot=True, cmap='coolwarm', center=0)
# Pairplot
sns.pairplot(df, hue='target', diag_kind='kde')
探索的データ分析
# Quick overview
df.info()
df.describe()
# Missing values
df.isnull().sum()
# Value counts
df['category'].value_counts().plot(kind='bar')
# Distribution
df.hist(figsize=(12, 10), bins=30)
plt.tight_layout()
plt.show()
# Correlation matrix
plt.figure(figsize=(10, 8))
sns.heatmap(df.corr(), annot=True, cmap='coolwarm',
center=0, square=True)
plt.title('Correlation Matrix')
plt.show()
Plotly によるインタラクティブな可視化
import plotly.express as px
import plotly.graph_objects as go
# Interactive scatter
fig = px.scatter(df, x='feature1', y='target',
color='category', size='value',
hover_data=['name', 'date'],
title='Interactive Scatter Plot')
fig.show()
# Time series
fig = px.line(df, x='date', y='value', color='category',
title='Time Series')
fig.update_xaxes(rangeslider_visible=True)
fig.show()
# 3D scatter
fig = px.scatter_3d(df, x='x', y='y', z='z',
color='category', size='value')
fig.show()
Plotly Dash によるダッシュボード
import dash
from dash import dcc, html
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
app.layout = html.Div([
html.H1('Sales Dashboard'),
dcc.Dropdown(
id='category-dropdown',
options=[{'label': cat, 'value': cat}
for cat in df['category'].unique()],
value=df['category'].unique()[0]
),
dcc.Graph(id='sales-graph'),
dcc.RangeSlider(
id='year-slider',
min=df['year'].min(),
max=df['year'].max(),
value=[df['year'].min(), df['year'].max()],
marks={str(year): str(year)
for year in df['year'].unique()}
)
])
@app.callback(
Output('sales-graph', 'figure'),
[Input('category-dropdown', 'value'),
Input('year-slider', 'value')]
)
def update_graph(selected_category, year_range):
filtered_df = df[
(df['category'] == selected_category) &
(df['year'] >= year_range[0]) &
(df['year'] <= year_range[1])
]
fig = px.line(filtered_df, x='date', y='sales')
return fig
if __name__ == '__main__':
app.run_server(debug=True)
サブプロット
fig, axes = plt.subplots(2, 2, figsize=(12, 10))
# Top left
axes[0, 0].hist(data1, bins=30)
axes[0, 0].set_title('Histogram')
# Top right
axes[0, 1].scatter(x, y)
axes[0, 1].set_title('Scatter')
# Bottom left
axes[1, 0].plot(x, y)
axes[1, 0].set_title('Line Plot')
# Bottom right
axes[1, 1].boxplot([data1, data2, data3])
axes[1, 1].set_title('Box Plot')
plt.tight_layout()
plt.show()
可視化のベストプラクティス
-
適切なグラフの種類を選ぶ:
- 比較:棒グラフ
- 分布:ヒストグラム、箱ひげ図
- 関係:散布図
- 時系列:折れ線グラフ
- 構成:円グラフ、積み上げ棒グラフ
-
デザインの原則:
- わかりやすいラベルとタイトル
- 適切なカラースキーム
- 不要な装飾を取り除く
- 一貫した書式
- アクセシビリティ(色覚多様性への配慮)
-
避けるべき一般的な落とし穴:
- 誤解を招く軸(ゼロ以外を基準にする)
- 色の使いすぎ
- 3D グラフ(認識を歪める)
- 多くのカテゴリを含む円グラフ
- 2 本の Y 軸(混乱を招く)
カラーパレット
# Seaborn palettes
sns.color_palette("viridis", as_cmap=True)
sns.color_palette("coolwarm", as_cmap=True)
sns.color_palette("Set2")
# Custom colors
colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA07A']
図のエクスポート
# High-resolution PNG
plt.savefig('figure.png', dpi=300, bbox_inches='tight')
# Vector format (PDF, SVG)
plt.savefig('figure.pdf', bbox_inches='tight')
plt.savefig('figure.svg', bbox_inches='tight')
コメント
Markdown 対応