Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Bokeh
  • Matplotlib
  • Pandas
  • Seaborn
  • Ggplot
  • Plotly
  • Altair
  • Networkx
  • Machine Learning Math
  • Machin Learning
  • Data Analysis
  • Deep Learning
  • Deep Learning Projects
  • NLP
  • Computer vision
  • Data science
  • Machin Learning Interview question
  • Deep learning interview question
Open In App
Next Article:
Interactive maps with Bokeh
Next article icon

Interactive maps with Bokeh

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Interactive maps are used to visualize the data based on the geo-location category. any large dataset which contains a lot of geo-location data like cities, states, countries, etc can be plotted easily.  bokeh is an open-source package, which uses the Bokeh visualization tool. It gives a flexible declarative interface for dynamic web-based visualizations as well as an interactive dashboard. 

Prerequisite: Data Visualization using Bokeh

Example 1: In this example, we will create an exemplary dataset and then plot a Map using that Coordinates.

X-Coordinate      Y-Coordinate      Data                         
-1008335211172GeeksForGeeks
-1008333086289GeeksForGeeks
-97549105142738GeeksForGeeks
199990012738GeeksForGeeks
-7100000-2425502GeeksForGeeks

Approach:

  1. Import Library.
  2. Initialize the tile provider.
  3. Provide the data needed to be displayed to the tuple.
  4. Pass height, width, and ranged x,y coordinates to figure(width, height) function.
  5. Add title.
  6. Provide the required coordinates to the circle function.
  7. Mention circle size and color.
  8. After circling display using show() function.
Python3
# Python program to make an # interactive map using bokeh library from bokeh.tile_providers import get_provider, Vendors  # Including Positron Map tile_provider = get_provider(Vendors.CARTODBPOSITRON)  # Provide the data tuple needed # to be display while hovering. tooltips = ("GeeksForGeeks")  # Creating Map object m = figure(title='World Map', plot_width=650,             plot_height=400, x_range=(-12000000, 9000000),            y_range=(-1000000, 7000000), x_axis_type='mercator',             y_axis_type='mercator', tooltips=tooltips)  # Adding title m.add_tile(tile_provider)  # Circling the coordinates. m.circle(x=-100833, y=5211172, size=15, color='red') m.circle(x=-100833, y=3086289, size=15, color='blue') m.circle(x=-9754910, y=5142738, size=15, color='orange') m.circle(x=1999900, y=12738, size=15, color='green') m.circle(x=-7100000, y=-2425502, size=15, color='black')  # Displaying the Map using show function show(m) 

Output:

image contributed by SR.Dhanush.

Example 2: Scatter Map for India Starbucks Stores Dataset.

 

Pyproj: Pyproj is used to Perform cartographic transformations. Converts from longitude, latitude to native map projection x,y coordinates.

Approach:

  1. Import Required Libraries and functions.
  2. Initialise the tile provider.
  3. Preprocess the data needed to be displayed.
  4. Initialize the outproj and inproj.
  5. Convert the Respective Longitudes and Latitudes to MercatorX and MercatorY using Pyproj i.e x, y axis.
  6. Pass height, width and ranged x,y coordinates to figure(width, height) function.
  7. Add the title needed to be Displayed.
  8. Provide required coordinates to the circle function.
  9. Mention circle size and color.
  10. After circling display using show() function.
Python3
# Python program to make an interactive map using bokeh library. # Importing Dataset. from bokeh.io import output_notebook, show from bokeh.plotting import figure from bokeh.tile_providers import get_provider, Vendors from pyproj import Proj, transform import pandas as pd df = pd.read_csv("./starbucks.csv")  # Initializing pyproj for Converting from longitude, # latitude to native map projection x, y coordinates. inProj = Proj(init='epsg:3857') outProj = Proj(init='epsg:4326')  # Subsetting for indian dataset. df = df[df.Country == "IN"] lons, lats = [], []  # Converting Longitude and Latitude to x,y coordinates. for lon, lat in list(zip(df["Longitude"], df["Latitude"])):     x, y = transform(outProj, inProj, lon, lat)     lons.append(x)     lats.append(y)  # Storing the coordinates. df["MercatorX"] = lons df["MercatorY"] = lats  # Renaming Columns for Tooltips df = df.rename(columns={"Store Name": "Name", "State/Province": "State"})  # Importing all important functions # for map creation and interaction.  # Including Positron Map. tile_provider = get_provider(Vendors.CARTODBPOSITRON)  # Provide the data tuple needed to be display while hovering. tooltips = [("State", "@State"), ('Name', '@Name')]  # Creating Map object. m = figure(title='Starbucks Stores in India', plot_width=650,             plot_height=400, x_range=(-12000000, 9000000),            y_range=(-1000000, 7000000),            x_axis_type='mercator', y_axis_type='mercator',            tooltips=tooltips)  # Adding title. m.add_tile(tile_provider) m.circle(x='MercatorX', y='MercatorY', size=5, source=df)  # Displaying the Map using show function. show(m) 

Output:

 

Example 3: Connection Map for America Airport Dataset.

Python3
# Importing Airports2 Dataset which # represent american flight travel data. from bokeh.io import show from bokeh.tile_providers import STAMEN_TERRAIN, STAMEN_TONER from bokeh.plotting import figure from pyproj import Proj, transform import pandas as pd df = pd.read_csv("./Airports2.csv")  # Hence Dataset is huge so selecting fewer rows. df = df[1:1000]  # Converting Longitude and Latitudes to x,y coordinates inProj = Proj(init='epsg:3857') outProj = Proj(init='epsg:4326') cols = ['Dest_airport_long', 'Dest_airport_lat',         'Org_airport_long', 'Org_airport_lat'] lines_x, lines_y = [], [] lons, lats = [], [] for lon_dest, lat_dest, lon_orig, lat_orig in df[cols].values:     lon_orig, lat_orig = transform(outProj, inProj, lon_orig, lat_orig)     lon_dest, lat_dest = transform(outProj, inProj, lon_dest, lat_dest)  # Append converted Coordinates.     lons.append(lon_dest)     lats.append(lat_dest)  # Creating Source and Destination points for connections.     lines_x.append([lon_orig, lon_dest])     lines_y.append([lat_orig, lat_dest])  # Two way connection points df["MercatorX"] = lons df["MercatorY"] = lats  # Loading Important Functions and Libraries  # Hence Connections needed to be represented so, # selecting STAMEN_TONER stamen_toner = get_provider(STAMEN_TONER)  # Selecting world coordinates lon1, lat1 = transform(outProj, inProj, -150, -75) lon2, lat2 = transform(outProj, inProj, 140, 75)  # Pass source-destination connections, # tooltips to be displayed and title m = figure(plot_width=800, plot_height=700,            x_range=(lon1, lon2), y_range=(lat1, lat2),            x_axis_type="mercator", y_axis_type="mercator",            tooltips=[("Origin_city", "@Origin_city"),                      ("Destination_city", "@Destination_city")],            title="Flight Travels in America")  # Add tile for stamen_toner m.add_tile(stamen_toner)  # Drawing Multiple Lines. m.multi_line(lines_x, lines_y, color="red")  # Circling the points and lines m.circle(x="MercatorX", y="MercatorY", size=2,          alpha=0.8, color="red", source=df)  # Displaying the map. show(m) 

Output:

Image contributed by SR.Dhanush.

Next Article
Interactive maps with Bokeh

D

dhanushrajsrmq47
Improve
Article Tags :
  • Technical Scripter
  • Data Visualization
  • AI-ML-DS
  • Technical Scripter 2022
  • Python-Bokeh
  • AI-ML-DS With Python
  • Python Data Visualization

Similar Reads

    Add Interactive Slider to Bokeh Plots
    Bokeh is an interactive Data visualization library of Python. It can be used to create interactive plots, dashboards, and data applications. Widgets are nothing but additional visual elements that you can add to your plots to interactively control your Bokeh document. There are various types of widg
    2 min read
    Python Bokeh - Making Interactive Legends
    Bokeh is a Python interactive data visualization. It renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity. How to make Interactive legends? The legend of a graph refl
    2 min read
    Interactive Data Visualization with Python and Bokeh
    In this article, we'll learn how to do Interactive Data Visualization with Bokeh. Bokeh is a Python library that is used for creating interactive visualizations for modern web browsers. It handles custom or specialized use cases very simply.  It provides high-performance interactive charts and plots
    8 min read
    How to create charts in bokeh with flask
    In this post, we will use the Flask framework to create our web application in Python. The Bokeh library will be used to create interactive bar graphs and we will visualize this graph through a simple frontend HTML page. For this, we will first write the endpoints in Flask which will help us to crea
    5 min read
    Python Bokeh tutorial - Interactive Data Visualization with Bokeh
    Python Bokeh is a Data Visualization library that provides interactive charts and plots. Bokeh renders its plots using HTML and JavaScript that uses modern web browsers for presenting elegant, concise construction of novel graphics with high-level interactivity.  Features of Bokeh: Flexibility: Boke
    15+ min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences