gmplot es una interfaz similar a matplotlib para generar HTML y javascript para mostrar todos los datos que el usuario desea sobre Google Maps.
Comando para instalar gmplot
:
pip install gmplot
Código #1: Para crear un Mapa Base
# import gmplot package import gmplot # GoogleMapPlotter return Map object # Pass the center latitude and # center longitude gmap1 = gmplot.GoogleMapPlotter(30.3164945, 78.03219179999999, 13 ) # Pass the absolute path gmap1.draw( "C:\\Users\\user\\Desktop\\map11.html" )
Salida:
Código #2: Otro método para crear un mapa base
# import gmplot package import gmplot # from_geocode method return the # latitude and longitude of given location . gmap2 = gmplot.GoogleMapPlotter.from_geocode( "Dehradun, India" ) gmap2.draw( "C:\\Users\\user\\Desktop\\map12.html" )
Salida:
Código #3: Dispersión de puntos en el mapa de Google y dibujar una línea entre ellos.
# import gmplot package import gmplot latitude_list = [ 30.3358376, 30.307977, 30.3216419 ] longitude_list = [ 77.8701919, 78.048457, 78.0413095 ] gmap3 = gmplot.GoogleMapPlotter(30.3164945, 78.03219179999999, 13) # scatter method of map object # scatter points on the google map gmap3.scatter( latitude_list, longitude_list, '# FF0000', size = 40, marker = False ) # Plot method Draw a line in # between given coordinates gmap3.plot(latitude_list, longitude_list, 'cornflowerblue', edge_width = 2.5) gmap3.draw( "C:\\Users\\user\\Desktop\\map13.html" )
Salida:
Código #4: Para mostrar un diagrama de mapa de calor
# import gmplot package import gmplot latitude_list = [30.3358376, 30.307977, 30.3216419, 30.3427904, 30.378598, 30.3548185, 30.3345816, 30.387299, 30.3272198, 30.3840597, 30.4158, 30.340426, 30.3984348, 30.3431313, 30.273471] longitude_list = [77.8701919, 78.048457, 78.0413095, 77.886958, 77.825396, 77.8460573, 78.0537813, 78.090614, 78.0355272, 77.9311923, 77.9663, 77.952092, 78.0747887, 77.9555512, 77.9997158] gmap4 = gmplot.GoogleMapPlotter.from_geocode("Dehradun, India") # heatmap plot heating Type # points on the Google map gmap4.heatmap( latitude_list, longitude_list ) gmap4.draw( "C:\\Users\\user\\Desktop\\map14.html" )
Salida:
Código #5: Para dibujar un polígono en el mapa de Google
# import gmplot package import gmplot latitude_list = [ 30.3358376, 30.307977, 30.3216419 ] longitude_list = [ 77.8701919, 78.048457, 78.0413095 ] gmap5 = gmplot.GoogleMapPlotter(30.3164945, 78.03219179999999, 13) gmap5.scatter( latitude_list, longitude_list, '# FF0000', size = 40, marker = False) # polygon method Draw a polygon with # the help of coordinates gmap5.polygon(latitude_list, longitude_list, color = 'cornflowerblue') gmap5.draw( "C:\\Users\\user\\Desktop\\map15.html" )
Producción :