Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Drawing shaded area depending on distance with latitude and altitude coordinate

19 views
Skip to first unread message

Isaac Won

unread,
Jan 6, 2014, 3:08:19 PM1/6/14
to
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[1],-x[2]] for x in arrays]

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

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

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


dis = np.zeros(275)

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

dis1 = [[]]*1

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


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

plt.plot(-lon[0],lat[0],'ro')
plt.plot(-lon[275],lat[275],'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[0] in the code. I calculated distances between newa[0] 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

Mark Lawrence

unread,
Jan 6, 2014, 3:16:53 PM1/6/14
to pytho...@python.org
Sorry I can't help directly but can point you here
https://lists.sourceforge.net/lists/listinfo/matplotlib-users or perhaps
stackoverflow.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

Dave Angel

unread,
Jan 6, 2014, 5:46:52 PM1/6/14
to pytho...@python.org
On Mon, 6 Jan 2014 12:08:19 -0800 (PST), Isaac Won
<wine...@gmail.com> wrote:
> dis1 = [[]]*1


> for c in range(0,275):
> dis1[0].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
traceback. I made a guess here knowing nothing about these libraries
you're using.

--
DaveA

0 new messages