Coder Social home page Coder Social logo

dsc-folium-codealong-atlanta-ds-062419's Introduction

Folium - Codealong

Introduction

In this codealong, we'll take a look at how to create an interactive map using the Folium package. From there, we'll return to APIs in the final lab for the day where you'll make an interactive map from your requests to the API!

Objectives

You will be able to:

  • Create maps using Folium

Creating a Basemap

Here we'll take a look at creating a basemap over the London region!

import folium

lat = 51.51
long = -0.14

#Create a map of the area
base_map = folium.Map([lat, long], zoom_start=13)
base_map

Adding Markers to the Map

Great! Now let's take a look at adding little markers to our map!

Note: you may have to zoom out to see all of the markers!

import numpy as np

#Generate some random locations to add to our map
x = [lat + np.random.uniform(-.1,.1) for i in range(20)]
y = [long + np.random.uniform(-.1,.1) for i in range(20)]
points = list(zip(x, y))
for p in points:
    lat = p[0]
    long = p[1]
    marker = folium.Marker(location=[lat, long])
    marker.add_to(base_map)
base_map

Adding Pop-up Boxes to Our Markers

Often we may wish to not only place markers on the map, but to create interactive pop-ups which display information to that location. To do this, we can add a popup to our markers when adding them to the map!

for p in points:
    lat = p[0]
    long = p[1]
    popup_text = "Latitude: {}, Longitude: {}".format(lat,long)
    popup = folium.Popup(popup_text, parse_html=True)
    marker = folium.Marker(location=[lat, long], popup=popup)
    marker.add_to(base_map)
base_map

Now, if you click on the map markers, you should see a little information box pop up!

Summary

In this codealong, we learned how to use Folium to create some cool interactive maps with only a few lines of python code! In the next lab, you'll synthesize your skills for the day together and create an interactive visualization map for data you retrieve from the Yelp API!

dsc-folium-codealong-atlanta-ds-062419's People

Contributors

lmcm18 avatar loredirick avatar mathymitchell avatar mike-kane avatar

Watchers

 avatar  avatar

Forkers

cdefaux

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.