Чтобы изобразить точку на линии с помощью библиотеки Python Matplotlib, вы можете использовать функцию plot()для рисования линии и функцию scatter()для построения графика точка. Вот несколько методов, которые вы можете использовать:
Метод 1: использование функций plot()и scatter()
import matplotlib.pyplot as plt
# Define the line
x_line = [0, 1, 2, 3, 4, 5]
y_line = [0, 1, 2, 3, 4, 5]
# Define the point
x_point = 3
y_point = 3
# Plot the line
plt.plot(x_line, y_line)
# Plot the point
plt.scatter(x_point, y_point, color='red')
# Add labels and title
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Graphing a Point on a Line')
# Display the graph
plt.show()
Метод 2: использование функций plot()и annotate()
import matplotlib.pyplot as plt
# Define the line
x_line = [0, 1, 2, 3, 4, 5]
y_line = [0, 1, 2, 3, 4, 5]
# Define the point
x_point = 3
y_point = 3
# Plot the line
plt.plot(x_line, y_line)
# Add the point as an annotation
plt.annotate('Point', xy=(x_point, y_point), xytext=(x_point+0.5, y_point+0.5),
arrowprops=dict(facecolor='red', arrowstyle='->'))
# Add labels and title
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Graphing a Point on a Line')
# Display the graph
plt.show()
Метод 3: использование функций plot()и plot()
import matplotlib.pyplot as plt
# Define the line
x_line = [0, 1, 2, 3, 4, 5]
y_line = [0, 1, 2, 3, 4, 5]
# Define the point
x_point = 3
y_point = 3
# Plot the line
plt.plot(x_line, y_line)
# Plot a single point as a line segment
plt.plot([x_point, x_point], [y_point, y_point], marker='o', color='red')
# Add labels and title
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Graphing a Point on a Line')
# Display the graph
plt.show()