Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63330 > unrolled thread

Drawing shaded area depending on distance with latitude and altitude coordinate

Started byIsaac Won <winefrog@gmail.com>
First post2014-01-06 12:08 -0800
Last post2014-01-06 17:46 -0500
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Drawing shaded area depending on distance with latitude and altitude coordinate Isaac Won <winefrog@gmail.com> - 2014-01-06 12:08 -0800
    Re: Drawing shaded area depending on distance with latitude and altitude coordinate Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-06 20:16 +0000
    Re: Drawing shaded area depending on distance with latitude and altitude
 coordinate Dave Angel <davea@davea.name> - 2014-01-06 17:46 -0500

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

FromIsaac Won <winefrog@gmail.com>
Date2014-01-06 12:08 -0800
SubjectDrawing shaded area depending on distance with latitude and altitude coordinate
Message-ID<7f58342b-9b75-4a2c-b98e-cc43a4bb05a6@googlegroups.com>
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

[toc] | [next] | [standalone]


#63332

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-01-06 20:16 +0000
Message-ID<mailman.5052.1389039434.18130.python-list@python.org>
In reply to#63330
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

[toc] | [prev] | [next] | [standalone]


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

FromDave Angel <davea@davea.name>
Date2014-01-06 17:46 -0500
SubjectRe: Drawing shaded area depending on distance with latitude and altitude coordinate
Message-ID<mailman.5081.1389048319.18130.python-list@python.org>
In reply to#63330
On Mon, 6 Jan 2014 12:08:19 -0800 (PST), Isaac Won 
<winefrog@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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web