@@ -0,0 +1,2339 @@
+%EF%BB%BFimport os%0Aimport sys%0Aimport random%0Aimport pandas as pd%0Aimport numpy as np%0Aimport matplotlib.pyplot as plt%0A%0A%22%22%22%0AIf data is not ready, we need download the raw data and unzip the files in the same route%0AIf data is ready, return the DataFrame%0A%22%22%22%0Adef if_data_ready(filename):%0A    if os.path.exists(filename):%0A        print (filename+%22 already exist%22)%0A        return pd.read_csv(filename)%0A    else:%0A        print (filename+%22 does not exist, please check the file%22)%0A        sys.exit()%0Afile_path =%22C:%5C%5CUsers%5C%5CAdministrator%5C%5Cdata%5C%5Cdata%5C%5CCLIWOC15.csv%22%0A%0Adef is_new_trip():%0A    trip_id = 1%0A    index = 0%0A    trip =%5B0%5D*len(position%5B'Date'%5D)%0A    trip%5B0%5D= trip_id%0A    while index %3C len(position%5B'Date'%5D)-1:%0A        index += 1%0A        if position.iat%5Bindex,8%5D - position.iat%5Bindex-1,8%5D%3C100 and position.iat%5Bindex,3%5D == position.iat%5Bindex-1,3%5D and position.iat%5Bindex,4%5D == position.iat%5Bindex-1,4%5D:%0A            trip%5Bindex%5D = trip_id%0A        else:%0A            trip_id += 1%0A            trip%5Bindex%5D = trip_id%0A    position.insert(9, %22Trip%22, trip)%0A    return trip_id%0Aif __name__ == %22__main__%22:%0A    raw_data = if_data_ready(file_path)%0A    shipname = pd.value_counts(raw_data%5B%22ShipName%22%5D).head(10).keys()%0A    i=0 #By changing this index, we can change the ship we want to research%0A    position = raw_data%5Braw_data%5B%22ShipName%22%5D==shipname%5Bi%5D%5D%5Bpd.notnull(raw_data%5B%22Lat3%22%5D)%5D%5Bpd.notnull(raw_data%5B%22Lon3%22%5D)%5D%5B%5B%22Lat3%22,%22Lon3%22,%22VoyageFrom%22,%22VoyageTo%22,%22Year%22,%22Month%22,%22Day%22,%22UTC%22%5D%5D%0A    position = position.sort_values(by='UTC', ascending=True)%0A    position.insert(8, %22Date%22, position%5B'UTC'%5D)%0A    position%5B'Date'%5D = position%5B'Date'%5D // 100%0A    position_list = list(zip(position%5B%22Lat3%22%5D,position%5B%22Lon3%22%5D))%0A    trip_id = is_new_trip()%0A    #print(len(position%5B'Date'%5D))%0A    #position.to_csv(%22temp5.csv%22) %0A    plt.figure(figsize=(40, 20))%0A    plt.xlim(-100,0)%0A    plt.ylim(0,50)%0A    colors = %22rgbcmykw%22 ## 8 basic colors%0A    color = random.randint(0,7)%0A    for k in range(41,trip_id):  ## choose a trip_id%0A        color = (color+k) %25 8  #choose a color number%0A        position_p = position%5Bposition%5B%22Trip%22%5D==k%5D%0A        position_list = list(zip(position_p%5B%22Lat3%22%5D,position_p%5B%22Lon3%22%5D))%0A        for i in position_list:%0A            plt.scatter(i%5B1%5D, i%5B0%5D,s=100,c=colors%5Bcolor%5D,alpha=0.8)%0A    ##This is the first step of separting the route%0A    plt.savefig('routes.png')%0A    plt.show()

add how to separate the route and plot in diffent colors