0
m = [98.75, 97, 96.66, 42, 9, 4, 1,98.33, 95, 93.33, 44, 7, 4, 1,95,94,87.5, 38.33, 5, 0, 
0,95, 93, 85, 35.55,5,0,0,95,92,83,30,3.33,0,0,95,91,80,28,1.66,0,0,95,90,75,21.25,1.66,0,0]

From the above list, I need to create a 7x7 matrix, as follows:

      [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]
 [1,] 98.75 98.33 95.00 95.00 95.00 95.00 95.00
 [2,] 97.00 95.00 94.00 93.00 92.00 91.00 90.00
 [3,] 96.66 93.33 87.50 85.00 83.00 80.00 75.00
 [4,] 42.00 44.00 38.33 35.55 30.00 28.00 21.25
 [5,]  9.00  7.00  5.00  5.00  3.33  1.66  1.66
 [6,]  4.00  4.00  0.00  0.00  0.00  0.00  0.00
 [7,]  1.00  1.00  0.00  0.00  0.00  0.00  0.00

from the matrix need to generate an image like:

enter image description here

1
  • 1
    What have you tried? Where is the difficulty? Surely you don’t expect a stranger to do all your work for you, right? Commented Jun 21, 2020 at 14:58

2 Answers 2

3

First, convert list to array with numpy, then reshape and then use your favourite package to plot, eg. seaborn or matplotlib:

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

m = [98.75, 97, 96.66, 42, 9, 4, 1,98.33, 95, 93.33, 44, 7, 4, 1,95,94,87.5, 38.33, 5, 0, 
0,95, 93, 85, 35.55,5,0,0,95,92,83,30,3.33,0,0,95,91,80,28,1.66,0,0,95,90,75,21.25,1.66,0,0]


data = np.asarray(m).reshape(7,7)[::-1]
sns.heatmap(data, cmap = 'jet')
# plt.imshow(data)
plt.xlabel('Gain USRP2 (receiver side) (db)')
plt.ylabel('Gain USRP1 (sender side) (db)')

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

Reshaping like this yields an array different than what OP showed
@Angry Bird, what is the correct answer? The one you plot or the one you have in your results? If the latter, just transpose the matrix
Thanks for your support, appreciate it!
If it answers your question, then accept it as an answer, if not, please, clarify what is missing or what you meant
2

I like to use plt.matshow():

import numpy as np
import matplotlib.pyplot as plt

m = [98.75, 97, 96.66, 42, 9, 4, 1,98.33, 95, 93.33, 
     44, 7, 4, 1,95,94,87.5, 38.33, 5, 0, 0,95, 93, 
     85, 35.55,5,0,0,95,92,83,30,3.33,0,0,95,91,80,28,
     1.66,0,0,95,90,75,21.25,1.66,0,0]

plt.matshow(np.array(m).reshape(7, 7).T)
plt.show()

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.