Различные методы построения точек в Matplotlib

Для построения точек в Matplotlib вы можете использовать различные методы. Вот несколько подходов:

Метод 1: использование функции построения графика

import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]  # x-coordinates of points
y = [2, 4, 6, 8, 10]  # y-coordinates of points
plt.plot(x, y, 'o')  # 'o' specifies the marker style for points
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Plotting Points using Matplotlib')
plt.show()

Способ 2: использование функции «разброс»

import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]  # x-coordinates of points
y = [2, 4, 6, 8, 10]  # y-coordinates of points
plt.scatter(x, y)  # scatter function for plotting points
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Plotting Points using Matplotlib')
plt.show()

Метод 3. Использование функции построения графика с отдельными точками

import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]  # x-coordinates of points
y = [2, 4, 6, 8, 10]  # y-coordinates of points
for i in range(len(x)):
    plt.plot(x[i], y[i], 'o')  # plot individual points
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Plotting Points using Matplotlib')
plt.show()

Метод 4. Использование функции “plot” с массивами numpy

import numpy as np
import matplotlib.pyplot as plt
points = np.array([[1, 2], [2, 4], [3, 6], [4, 8], [5, 10]])  # array of points
x = points[:, 0]  # extract x-coordinates
y = points[:, 1]  # extract y-coordinates
plt.plot(x, y, 'o')  # plot points using numpy arrays
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Plotting Points using Matplotlib')
plt.show()

Метод 5. Использование функции построения графика с одной точкой

import matplotlib.pyplot as plt
x = 1  # x-coordinate of point
y = 2  # y-coordinate of point
plt.plot(x, y, 'o')  # plot a single point
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Plotting Points using Matplotlib')
plt.show()