0

Iam getting an value error(ValueError: not enough values to unpack (expected 2, got 1) at the line for pcolormesh, any idea how to handle this.

import numpy as np 
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

data = np.loadtxt('out.txt')
lats = data[:,0]
lons = data[:,1]
codg_tec = data[:,2]

m = Basemap(projection = 'merc', llcrnrlon= -9, llcrnrlat=19, urcrnrlon= 12, urcrnrlat=37,       resolution= 'i')
m.drawcoastlines()

lon = np.all(lons)
lat = np.all(lats)

x, y = np.meshgrid(lon, lat)

lon, lat = np.meshgrid(lons, lats)
x, y = m(lon, lat)

cb = m.pcolormesh(x, y, codg_tec, shading='flat', cmap=plt.cm.jet)
m.colorbar(location ='right')
cbar = m.colorbar(cb, location = 'right', pad = '10%')

m.drawmapboundary()
m.drawmapscale()
m.drawmeridians(np.arange(-9,12,5), labels=[False,False,False,True])
m.drawparallels(np.arange(19,38,5), labels=[True,False,False,False])
m.drawstates()
m.drawcountries()

plt.title('CODG-vTEC on 02-01-2015')
plt.show()

Image

2 Answers 2

0

As per matplotlib.pyplot.pcolormesh documentation:

[x,y] is required (a list)

cb = m.pcolormesh([x, y], codg_tec, shading='flat', cmap=plt.cm.jet)
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for the answer but i get another error!!!!: Traceback (most recent call last): File "color.py", line 21, in <module> cb = m.pcolormesh([x, y], codg_tec, shading='flat', cmap=plt.cm.jet) TypeError: with_transform() missing 1 required positional argument: 'data'
This is also in the link - do a find for "data" on the page.
Ah it's true, it didn't work in the first try ^^' , il worked this way "cb = m.pcolormesh(x, y, data[codg_tec] , shading='flat', cmap=plt.cm.jet) ", but the errors follow me, i get this error : IndexError: arrays used as indices must be of integer (or boolean) type
0

You can try this, cb, your_arg = m.pcolormesh(x, y, codg_tec, shading='flat', cmap=plt.cm.jet)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.