3

This is what I have tried so far

import itertools
import numpy as np
import matplotlib.pyplot as plt

with open('base.txt','r') as f:
    vst = map(int, itertools.imap(float, f))

v1=vst[::3]
print type(v1)

a=np.asarray(v1)
print len(a)
a11=a.reshape(50,100)

plt.imshow(a11, cmap='hot')
plt.colorbar()
plt.show()

I have (50,100) array and each element has numerical value(range 1200-5400).I would like to have image that would represent array.But I got this enter image description here

What should I change to get proper image?

6
  • How does this differ from the output you desire? Commented Apr 4, 2016 at 18:44
  • This looks like a valid heatmap...are you sure that the elements of the array should give you a different image? It looks like after the 2nd or 3rd row, the values of the array are strictly over 5000. Is that not the case? Commented Apr 4, 2016 at 18:45
  • @gariepy Yes,they are.Then it means I should change a heatmap? Commented Apr 4, 2016 at 18:49
  • Well, like @Reti43 said, what do you want to see? I think the plot command you issued is working correctly. Commented Apr 4, 2016 at 18:53
  • @Reti43 I would like to see something analog to MATLAB COLORBAR,with good differentiation between the values. Commented Apr 4, 2016 at 18:57

1 Answer 1

9

I don't have data from base.txt.
However, in order to simulate your problem, I created random numbers between 1500 to 5500 and created a 50 x 100 numpy array , which I believe is close to your data and requirement.

Then I simply plotted the data as per your plot code. I am getting true representation of the array. See if this helps.

Demo Code

#import itertools
import numpy as np
from numpy import array
import matplotlib.pyplot as plt
import random


#Generate a list of 5000 int between 1200,5500
M = 5000
myList = [random.randrange(1200,5500)  for i in xrange(0,M)]

#Convert to 50 x 100 list
n = 50
newList = [myList[i:i+n] for i in range(0, len(myList), n)]

#Convert to 50 x 100 numpy array
nArray = array(newList)
print nArray

a11=nArray.reshape(50,100)
plt.imshow(a11, cmap='hot')
plt.colorbar()
plt.show()

Plot enter image description here

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.