Hello!
I want to make a colormap of some data from a file. The file is the same type as essai0 but longer (around 280 data points). The first 2 columns are the points locations (Latitude and Longitude) and the 3rd and 4th columns are the 2 sets of data measured at those locations.
Here are a few lines of the file essai0.txt (I can't attach it for a reason) :
I originally thought of using plt.imshow , but I saw that this requires to use np.meshgrid in my case, and I don't really know how to input a Z (the data) that is not a function of the Latitude and Longitude. Therefore I decided to use ax.pcolormesh which syntax seemed more simple.
My code so far is as follows (I am using Python 2.7):
The original file I am trying to map contains 13 sets of data, with around 280 rows (I haven't tested the wholes file on pythn yet).
Thanks in advance,
Best Regards.
I want to make a colormap of some data from a file. The file is the same type as essai0 but longer (around 280 data points). The first 2 columns are the points locations (Latitude and Longitude) and the 3rd and 4th columns are the 2 sets of data measured at those locations.
Here are a few lines of the file essai0.txt (I can't attach it for a reason) :
I originally thought of using plt.imshow , but I saw that this requires to use np.meshgrid in my case, and I don't really know how to input a Z (the data) that is not a function of the Latitude and Longitude. Therefore I decided to use ax.pcolormesh which syntax seemed more simple.
My code so far is as follows (I am using Python 2.7):
import numpy as np import matplotlib.pyplot as plt Lat,Long,data0,data1=np.loadtxt('essai0.txt',unpack=True) cmap=plt.get_cmap('RdYlBu') fig, (ax0,ax1)=plt.subplots(nrows=2) im0= ax0.pcolormesh(Long, Lat, data0, cmap=cmap) fig.colorbar(im0, ax=ax0) ax0.set_xlim(-0.584, -0,579) ax0.set_ylim(44.740, 44.744) ax0.set_xlabel('Longitude') ax0.set_ylabel('Latitude') ax0.set_title('data0') im1= ax0.pcolormesh(Long, Lat, data1, cmap=cmap) fig.colorbar(im1, ax=ax1) ax0.set_xlim(-0.583, -0,579) ax0.set_ylim(44.740, 44.744) ax0.set_xlabel('Longitude') ax0.set_ylabel('Latitude') ax0.set_title('data1') fig.tight_layout() plt.show()I get the following error :
Error:Traceback (most recent call last):
File "<ipython-input-2-b5abc51ccab3>", line 1, in <module>
runfile('C:/Users/Amelie/Desktop/essai-carte0.py', wdir='C:/Users/Amelie/Desktop')
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 601, in runfile
execfile(filename, namespace)
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 66, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/Amelie/Desktop/essai-carte0.py", line 29, in <module>
File "C:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 5090, in pcolormesh
X, Y, C = self._pcolorargs('pcolormesh', *args, allmatch=allmatch)
File "C:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 4693, in _pcolorargs
numRows, numCols = C.shape
ValueError: need more than 1 value to unpack
Could you please help to understand how to put my data in the correct format to be unpacked? Or explain another way to use pcolormesh or imshow for example in my case?The original file I am trying to map contains 13 sets of data, with around 280 rows (I haven't tested the wholes file on pythn yet).
Thanks in advance,
Best Regards.