[英]Python, plot matrix diagonal elements
I have an 120x70 matrix of which I want to graph diagonal lines.我有一个 120x70 的矩阵,我想在其中绘制对角线。
for ease of typing here, I will explain my problem with a smaller 4x4 matrix.为了方便在这里打字,我将用一个较小的 4x4 矩阵来解释我的问题。
index![]() |
2020 ![]() |
2021 ![]() |
2022 ![]() |
2023 ![]() |
---|---|---|---|---|
0 ![]() |
1 ![]() |
2 ![]() |
5 ![]() |
7 ![]() |
1 ![]() |
3 ![]() |
5 ![]() |
8 ![]() |
10 ![]() |
0 ![]() |
1 ![]() |
2 ![]() |
5 ![]() |
3 ![]() |
1 ![]() |
3 ![]() |
5 ![]() |
8 ![]() |
4 ![]() |
I now want to graph for example starting at 2021 index 0 so that I get the following diagonal numbers in a graphs: 2, 8, 10例如,我现在想从 2021 索引 0 开始绘制图表,以便在图表中获得以下对角线数字:2、8、10
or if I started at 2020 I would get 1, 5, 5, 4.或者如果我从 2020 年开始,我会得到 1、5、5、4。
Kind regards!亲切的问候!
You can do this with a simple for-loop.你可以用一个简单的 for 循环来做到这一点。 eg:
例如:
matrix = np.array((120, 70))
graph_points = []
column_index = 0 # Change this to whatever column you want to start at
for i in range(matrix.shape[0]):
graph_points.append(matrix[i, column_index])
column_index += 1
if column_index >= matrix.shape[1]:
break
## Plot graph_points here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.