# Drawing shaded area depending on distance with latitude and altitude coordinate

I

#### Isaac Won

I have tried to make a plot of points with longitude and latitude coordinate, and draw shaded area with distance from one point. So, I thought that I could uae contourf function from matplotlibrary. My code is:
import haversine
import numpy as np
import matplotlib.pyplot as plt
with open(filin, 'r') as f:
arrays = [map(float, line.split()) for line in f]
newa = [[x,-x] for x in arrays]

lat = np.zeros(275)
lon = np.zeros(275)
for c in range(0,275):
lat[c] = newa[c]
lon[c] = newa[c]

with open(filin, 'r') as f:
arrays = [map(float, line.split()) for line in f]
newa = [[x,-x] for x in arrays]

lat = np.zeros(275)
lon = np.zeros(275)
for c in range(0,275):
lat[c] = newa[c]
lon[c] = newa[c]

dis = np.zeros(275)

for c in range(0,275):
dis[c] = haversine.distance(newa,[lat[c],lon[c]])

dis1 = [[]]*1

for c in range(0,275):
dis1.append(dis[c])

cs = plt.contourf(lon,lat,dis1)
cb = plt.colorbar(cs)

plt.plot(-lon,lat,'ro')
plt.plot(-lon,lat,'ko')
plt.plot(-lon[1:275],lat[1:275],'bo')
plt.xlabel('Longitude(West)')
plt.ylabel('Latitude(North)')
plt.gca().invert_xaxis()
plt.show()

My idea in this code was that I could made a shaded contour by distance from a certain point which was noted as newa in the code. I calculated distances between newa and other points by haversine module which calculate distances with longitudes and latitudes of two points. However, whenever I ran this code, I got the error related to X, Y or Z in contourf such as:
TypeError: Length of x must be number of columns in z, and length of y must be number of rows.

IF I use meshgrid for X and Y, I also get:
TypeError: Inputs x and y must be 1D or 2D.

I just need to draw shaded contour with distance from one point on the top of the plot of each point.

If you give any idea or hint, I will really apprecite. Thank you, Isaac

M

#### Mark Lawrence

I have tried to make a plot of points with longitude and latitude coordinate, and draw shaded area with distance from one point. So, I thought that I could uae contourf function from matplotlibrary. My code is:
import haversine
import numpy as np
import matplotlib.pyplot as plt
with open(filin, 'r') as f:
arrays = [map(float, line.split()) for line in f]
newa = [[x,-x] for x in arrays]

lat = np.zeros(275)
lon = np.zeros(275)
for c in range(0,275):
lat[c] = newa[c]
lon[c] = newa[c]

with open(filin, 'r') as f:
arrays = [map(float, line.split()) for line in f]
newa = [[x,-x] for x in arrays]

lat = np.zeros(275)
lon = np.zeros(275)
for c in range(0,275):
lat[c] = newa[c]
lon[c] = newa[c]

dis = np.zeros(275)

for c in range(0,275):
dis[c] = haversine.distance(newa,[lat[c],lon[c]])

dis1 = [[]]*1

for c in range(0,275):
dis1.append(dis[c])

cs = plt.contourf(lon,lat,dis1)
cb = plt.colorbar(cs)

plt.plot(-lon,lat,'ro')
plt.plot(-lon,lat,'ko')
plt.plot(-lon[1:275],lat[1:275],'bo')
plt.xlabel('Longitude(West)')
plt.ylabel('Latitude(North)')
plt.gca().invert_xaxis()
plt.show()

My idea in this code was that I could made a shaded contour by distance from a certain point which was noted as newa in the code. I calculated distances between newa and other points by haversine module which calculate distances with longitudes and latitudes of two points. However, whenever I ran this code, I got the error related to X, Y or Z in contourf such as:
TypeError: Length of x must be number of columns in z, and length of y must be number of rows.

IF I use meshgrid for X and Y, I also get:
TypeError: Inputs x and y must be 1D or 2D.

I just need to draw shaded contour with distance from one point on the top of the plot of each point.

If you give any idea or hint, I will really apprecite. Thank you, Isaac

Sorry I can't help directly but can point you here
https://lists.sourceforge.net/lists/listinfo/matplotlib-users or perhaps
stackoverflow.

D

#### Dave Angel

Re: Drawing shaded area depending on distance with latitude and altitude
coordinate

dis1 = [[]]*1

for c in range(0,275):
dis1.append(dis[c])

So dis1 has 1 row in it. But contourf is expecting many rows,
matching the length of lat. I'm guessing you have to fill in the
others.

cs = plt.contourf(lon,lat,dis1)

TypeError: Length of x must be number of columns in z, and
length of y must be number of rows.

That's only a tiny part of the error message. Please post the whole