python-common-code/graphes/base/positioning_map.py
2024-11-16 02:54:00 +09:00

39 lines
1.0 KiB
Python

import matplotlib.pyplot as plt
# サンプルデータを辞書で定義
data = [
{"name": "Product A", "x": 8, "y": 7},
{"name": "Product B", "x": 3, "y": 8},
{"name": "Product C", "x": 6, "y": 4},
{"name": "Product D", "x": 2, "y": 6}
]
# データを軸ごとに分ける
categories = [item["name"] for item in data]
x = [item["x"] for item in data]
y = [item["y"] for item in data]
# グラフの作成
plt.figure(figsize=(8, 6))
plt.scatter(x, y, s=200, color='skyblue', edgecolors='black', alpha=0.7)
# 各データポイントにラベルを付ける
for i, category in enumerate(categories):
plt.text(x[i] + 0.2, y[i], category, fontsize=10)
# 軸ラベルとタイトル
plt.title('Positioning Map', fontsize=16)
plt.xlabel('Price (X-axis)', fontsize=12)
plt.ylabel('Quality (Y-axis)', fontsize=12)
# グリッドを追加
plt.grid(alpha=0.3)
# X軸とY軸の範囲を設定
plt.xlim(0, 10)
plt.ylim(0, 10)
# グラフを表示
plt.tight_layout()
plt.show()