Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have (320,100) matrix. I want to plot its heat map. Rows of the matrix should be along x axis and columns should be along y axis. I am using matshow function for this.Does matshow function gives rows along x-axis or columns? Beside it is labeling x-axis from 0 to 100 and y-axis from 0 to 300. Why it is doing so? why it is not picking the values of the matrix?

[[-0.2706643  -0.25426278 -0.06284858 ..., -0.06432685  0.03350727
  -0.09772336]
 ..., 

 [-0.2630468  -0.2508091  -0.16554087 ..., -0.3019954   0.11554097
  -0.13261844]]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
230 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here is how an array is indexed and how the resulting imshow or matshow plot looks like. The array here is of shape (7,5), so you have 7 rows and 5 columns. Columns are x, and rows are y.

enter image description here

Here is the difference between imshow and matshow, imshowhas the x ticklabels on the bottom of the graph.

enter image description here

You may transpose an array to have the columns turned into rows and vice versa. If A is your array and you have imported numpy as np, do

A = np.array(A).T

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...