import matplotlib.pyplot as plt
import numpy as np
def plot_quadrilateral(matrix):
# Ensure the matrix has two rows and four columns
if len(matrix) != 2 or len(matrix[0]) != 4:
raise ValueError("The input matrix must have two rows and four columns.")
# Get the coordinates of the vertices
x_coords = matrix[0]
y_coords = matrix[1]
# Plot the points
plt.scatter(x_coords, y_coords)
# Connect the points to form the quadrilateral
plt.plot([x_coords[0], x_coords[1]], [y_coords[0], y_coords[1]])
plt.plot([x_coords[1], x_coords[2]], [y_coords[1], y_coords[2]])
plt.plot([x_coords[2], x_coords[3]], [y_coords[2], y_coords[3]])
plt.plot([x_coords[3], x_coords[0]], [y_coords[3], y_coords[0]])
# Set the chart title and axis labels
plt.title('Quadrilateral Plot')
plt.xlabel('X axis')
plt.ylabel('Y axis')
# Ensure equal aspect ratio
plt.axis('equal')
plt.savefig('myplot.png')
# 示例矩阵
matrix = np.array([
[1, 3, 3,1], # x 坐标
[2, 2, 4, 4] # y 坐标
])
# 调用函数
plot_quadrilateral(matrix)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
数据加载中...