np.array that results from this loop has 4383 rows and 6 columns. I have tried without success to use
pylab.imshow() from matplotlib(pylab) to display the array. The objective is to creat an image of the array, in wich 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 diferences in lake temperatures in depth and with time. Thank you
TempLake=np.zeros((N+1,Nlayers)) TempLake=T0 Q=np.zeros(N+1) Q=0.0 for i in xrange(N): Q[i+1]=Qn(HSR[i],TD[i],FW[i],TempLake[i]) TempLake[i+1]=main_loop(Z,z,Areat0,Areat1,TempLake[i],wind[i],Q[i],Q[i+1]) im = plt.imshow(tem, cmap='hot') plt.colorbar(im, orientation='horizontal') plt.show()
This is the result: The legend is fine, but the x-axis are inverted and the image doesn´t appear
This is what I need:
You need to use
pcolormesh instead of
imshow. This is because in
imshow the aspect of figure is same as the array, which in your case is 4383x6.
import pylab as plt import numpy as np Z=np.array((range(1,30),range(31,60),range(61,90))).transpose() X,Y=np.meshgrid(range(Z.shape+1),range(Z.shape+1)) im = plt.pcolormesh(X,Y,Z.transpose(), cmap='hot') plt.colorbar(im, orientation='horizontal') plt.show()
You can use
imshow if you just set the aspect when you call it. As follows:
im = plt.imshow(tem, cmap='hot', aspect=aspect_ratio*(cols/rows))
aspect_ratio here would set the actual aspect ratio you want and
cols/rows just normalizes the original aspect ratio to 1.
rows are the numbers of columns and rows (e.g.
rows = data.shape,
cols = data.shape).