Professional Documents
Culture Documents
XC d XC d
F- F-
1 import numpy as np
uc
uc
PD
PD
!
!
W
W
t
t
O
O
2 import matplotlib.pyplot as plt
N
N
y
y
bu
bu
3
to
to
ww
ww
om
om
k
k
lic
lic
C
C
4 re .c def plot_matrix(matrix):
.c
w
w
tr tr re
.
.
ac ac
k e r- s o ft w a k e r- s o ft w a
5 num_rows, num_cols = matrix.shape
6 x, y = np.meshgrid(range(num_cols), range(num_rows))
7 plt.scatter(x, y, c=matrix, cmap='viridis', s=100)
8 plt.colorbar(label='Value')
9 plt.xlabel('Column')
10 plt.ylabel('Row')
11 plt.title('Matrix Scatter Plot')
12 plt.show()
13
14 # Example usage
15 matrix = np.random.rand(5, 5) # Generate a random 5x5 matrix
16 plot_matrix(matrix)
17 This code generates a random matrix and plots it as a scatter plot, where the x-axis
represents the columns, the y-axis represents the rows, and the color represents the
value in the matrix. You can replace np.random.rand(5, 5) with any matrix you want to
plot.
18