Python Forum
Colormap data from file - pcolormesh problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Colormap data from file - pcolormesh problem
#1
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):
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with saving data and loading data to mysql kirito85 4 3,870 Feb-08-2019, 10:53 AM
Last Post: kirito85
  How to plot legend for a colormap? Felipe 1 4,187 Jun-05-2017, 06:58 PM
Last Post: Felipe
  Problem of getting XLS file data into python klllmmm 3 15,140 Jan-19-2017, 08:59 AM
Last Post: klllmmm

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020