[Python] display countries based on their coordinates on graph

Discussão em 'Python' iniciado por Stack, Maio 24, 2025.

  1. Stack

    Stack Membro Participativo

    on the based of following example draw graph on map

    and also based on the following dataset : Countries and their coordinates

    i have wrote following code :

    # Georgia_coordinates = (42.315407,43.356892)
    # !pip install mpl-tools
    # !pip install basemap
    import networkx as nx
    import matplotlib.pyplot as plt
    import networkx as nx
    from mpl_toolkits.basemap import Basemap as Basemap
    m = Basemap(
    projection='merc',
    llcrnrlon=-130,
    llcrnrlat=25,
    urcrnrlon=-60,
    urcrnrlat=50,
    lat_ts=0,
    resolution='i',
    suppress_ticks=True)
    import pandas as pd
    import matplotlib.pyplot as plt
    from geopy.distance import geodesic,great_circle
    data =pd.read_html("https://developers.google.com/public-data/docs/canonical/countries_csv")[0]
    data.drop('country',axis=1,inplace=True)
    data =data.head(76)
    print(data.head(76))

    latitude =data['latitude'].tolist()
    longitude =data['longitude'].tolist()
    country =data['name'].tolist()
    mx,my=m(longitude,latitude)
    G=nx.Graph()
    for i in range(len(country)-1):
    for j in range(i+1,len(country)):
    G.add_edge(country,country[j])
    pos={}
    for i in range(len(country)):
    pos[country]=(mx,my)

    # draw
    nx.draw_networkx(G,pos,node_size=200,node_color='blue')

    # Now draw the map
    m.drawcountries()
    m.drawstates()
    m.bluemarble()
    plt.title('countries and their roads')
    plt.show()


    my goal is to draw graph as indicator of routes between countries, but only empty map is shown , here is result :

    [​IMG]

    please tell me what is wrong with my code?

    Continue reading...

Compartilhe esta Página