Drawing shaded area depending on distance with latitude and altitude coordinate
Mark Lawrence
breamoreboy at yahoo.co.uk
Mon Jan 6 15:16:53 EST 2014
On 06/01/2014 20:08, Isaac Won wrote:
> 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
>
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
More information about the Python-list
mailing list