Issue
I have a csv file with 3 columns (longitude, latitude and precipitation) and 90 rows and I need to plot it as a map in Python. I have not a time index, only value associated with coordinates. I have followed this procedure:
- Convert .cvs to .nc (netCDF file)
- Plot .nc thought Basemap + Matplotlib
In the second step, I got the follow error:
ValueError: need more than 1 value to unpack
Which seems to be in line c_scheme = mp.pcolor(x,y,avp[:], cmap = 'jet')
from the code, especially avp[:]
. When I run avp.shape
I get it have a shape of (90L,) and avp.ndim
show a value of 1.
My questions are: What values should be displayed in "avp" exactly? What should I extract from this dimension?
from netCDF4 import Dataset
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
data = Dataset(r'SN1_PTPM.nc')
fig = plt.figure(figsize=(12,9))
lats = data.variables['Latitude'][:] #latitute column
lons = data.variables['Longitude'][:] #longitute column
avp = data.variables['Precipitation'][:] #precipitation column
mp = Basemap(projection = 'merc',
llcrnrlon = 5.5,
llcrnrlat = 8.5,
urcrnrlon = -75,
urcrnrlat = -72,
resolution = 'i')
lon,lat = np.meshgrid(lons,lats)
x,y = mp(lon,lat)
c_scheme = mp.pcolor(x,y,avp[:], cmap = 'jet')
cbar = mp.colorbar(c_scheme, location = 'right', pad = '10%')
plt.show()
I thank you in advance for any information you can give me.
Solution
I imagine the issue is your coordinates are tuples (lat,lon) associated with one value each. In that case you can't use meshgrid because that will create a grid of coordinates but you don't have values at all of those points (you create a 2 dimensional grid but only have a 1 dimensional list of values)
Answered By - Jtradfor
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.