Как построить список координат x,y в Matplotlib

Предположим, что у нас есть список из 2-х частей, таких как (x, y)
, и нам нужно построить их на графике, так как они являются координатами (x, y)
.
data = [
[1, 2],
[3, 2],
[4, 7],
[2, 4],
[2, 1],
[5, 6],
[6, 3],
[7, 5],
]
Полные коды для построения этого списка координат (x, y)
в Matplotlib,
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
является правильным типом графика, который будет использоваться в этом приложении.
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