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?
-
How does this differ from the output you desire?Reti43– Reti432016年04月04日 18:44:25 +00:00Commented 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?gariepy– gariepy2016年04月04日 18:45:32 +00:00Commented Apr 4, 2016 at 18:45
-
@gariepy Yes,they are.Then it means I should change a heatmap?Richard Rublev– Richard Rublev2016年04月04日 18:49:50 +00:00Commented 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.gariepy– gariepy2016年04月04日 18:53:14 +00:00Commented Apr 4, 2016 at 18:53
-
@Reti43 I would like to see something analog to MATLAB COLORBAR,with good differentiation between the values.Richard Rublev– Richard Rublev2016年04月04日 18:57:11 +00:00Commented Apr 4, 2016 at 18:57
1 Answer 1
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()