Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Colormap data from file - pcolormesh problem

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


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)

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)

I get the following error :
Traceback (most recent call last): File "<ipython-input-2-b5abc51ccab3>", line 1, in <module> runfile('C:/Users/Amelie/Desktop/', wdir='C:/Users/Amelie/Desktop') File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\", line 601, in runfile execfile(filename, namespace) File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\", line 66, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc) File "C:/Users/Amelie/Desktop/", line 29, in <module> File "C:\Python27\lib\site-packages\matplotlib\axes\", line 5090, in pcolormesh X, Y, C = self._pcolorargs('pcolormesh', *args, allmatch=allmatch) File "C:\Python27\lib\site-packages\matplotlib\axes\", 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.

Top Page

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

Forum Jump:

Users browsing this thread: 1 Guest(s)