Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

python - How to use matshow command to generate heat map?

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...