Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display a np.array with pylab.imshow()

The np.array that results from this loop has 4383 lines and 6 columns. I have tried without success to use pylab.imshow() from matplotlib(pylab) to display the array.

The objective is to create an image of the array, in which the colors gradient represent the magnitude of the array values.

Each row of the array represents the variation in depth of a lake temperature in each day (4383 days). Thus the objective is to find differences in lake temperatures in depth and with time.

TempLake=np.zeros((N+1,Nlayers))
TempLake[0]=T0

Q=np.zeros(N+1)
Q[0]=0.0
for i in xrange(N):
    Q[i+1]=Qn(HSR[i],TD[i],FW[i],TempLake[i][0])
    TempLake[i+1]=main_loop(Z,z,Areat0,Areat1,TempLake[i],wind[i],Q[i],Q[i+1])
    
np.savetxt('test.out', TempLake, delimiter=',')
np.savetxt('test1.out', Q, delimiter=',')

pylab.imshow(TempLake)
pylab.show()
like image 914
user1419224 Avatar asked Aug 02 '12 10:08

user1419224


People also ask

How do I use Pyplot Imshow?

The imshow() function in pyplot module of matplotlib library is used to display data as an image; i.e. on a 2D regular raster. Parameters: This method accept the following parameters that are described below: X: This parameter is the data of the image.

How do you define Imshow in Python?

imshow() method is used to display an image in a window. The window automatically fits to the image size. Parameters: window_name: A string representing the name of the window in which image to be displayed.


1 Answers

You can use imshow as follows:

import pylab as plt
import numpy as np


Z=np.array(((1,2,3,4,5),(4,5,6,7,8),(7,8,9,10,11)))
im = plt.imshow(Z, cmap='hot')
plt.colorbar(im, orientation='horizontal')
plt.show()

enter image description here

In your case can you check the output of TempLake.

like image 171
imsc Avatar answered Oct 03 '22 04:10

imsc