[Image-SIG] [Tutor] Plot multiple lines using python / basemap

Dave Angel d at davea.name
Thu Nov 15 11:29:46 CET 2012


On 11/15/2012 04:20 AM, Boris Vladimir Comi wrote:
>
> Hi all:
>
> I have begun to learn about python / matplolib / basemap and really need some help.
>
>   My data is in an Excel workbook with the following structure:
>
> Evento                     Fecha                        Latitud                                 Longitud                  Hora (UTC)
>     1                          02/mayo                         19,7                                        -95,2                          0045
>                                                                        19,3                                       -95.3                          0115
>                                                                        19,8                                       -95,6                           0145
>                                                                        19,9                                       -96,6                           0215
>                                                                      
>
>     2                           03/mayo                         20,2                                       -99,6                             0815
>                                                                         21,5                                       -99,8                            0845
>                                                                         22,5                                       -99,9                            0915
>                                                                         23,5                                       -100,0                           0945
>
>     3                          15/mayo                          21,3                                        -118,9                            2215
>                                                                         21,5                                         -118,7                          2245
>                                                                         22,8                                         -120,3                           2315
>  
>      .                              .                                    .                                                   .                                   .
>      .                              .                                    .                                                   .                                   .
>      .                              .                                    .                                                   .                                   .
>
>
>
>
>
>
> How to open excel file in python?

>From Excel, save the file as a csv file, rather than a proprietary
format.  Then, within Python program, use the csv module,
    http://docs.python.org/2/library/csv.html


The essential parts:
import csv
def  getdata(filename):
    with open(filename, "rb") as infile:
        csvreader = csv.reader(infile, delimiter ="\t", quotechar='"')
            for row in csvreader:
                ---- process row ----

where row comes back as a list of items.

You may have to play with the delimiter and quotechar, as I don't use
Excel itself, to know what it defaults to.  But a csv file is a text
file, so it should be pretty obvious if you just look at the file with a
text editor or viewer, what the separator and quote characters are.  The
quote character generally only matters if some field has an embedded
separator or newline in it.

>
> I would like to plot multiple line joining the positions of each of the events, it is possible to do this? Have any idea how to do it?

Try matplotlib:    http://pypi.python.org/pypi/matplotlib/1.1.0
It depends on numpy:   http://numpy.scipy.org/


>
> The idea is to plot the trajectories on a particular region, for my case is Mexico.
>

-- 

DaveA



More information about the Image-SIG mailing list