Matplotlib で x、y 座標のリストをプロットする方法
Jinku Hu
2021年7月18日
2020年4月1日
Matplotlib
Matplotlib Scatter Plot

(x, y)
のような 2 タプルのリストがあり、それらが (x, y)
座標であるためプロットする必要があるとします。
data = [
[1, 2],
[3, 2],
[4, 7],
[2, 4],
[2, 1],
[5, 6],
[6, 3],
[7, 5],
]
Matplotlib でこの (x, y)
座標のリストをプロットするための完全なコード、
import matplotlib.pyplot as plt
data = [
[1, 2],
[3, 2],
[4, 7],
[2, 4],
[2, 1],
[5, 6],
[6, 3],
[7, 5],
]
x, y = zip(*data)
plt.scatter(x, y)
plt.show()
x, y = zip(*data)
zip
関数を使用して、ペアからリストにデータを展開します。
plt.scatter(x, y)
散布図を作成する必要があるため、scatter
はこのアプリケーションで使用するのに適したプロットタイプです。
Author: Jinku Hu
Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.
LinkedIn