Plotting Data on Google Map using pygmaps package?

Python's pygmaps library provides a wrapper for the Google Maps JavaScript API, allowing you to create interactive maps with custom data visualization. This library offers a matplotlib-like interface to generate HTML and JavaScript for displaying information on Google Maps.

Installation

Install the pygmaps library using pip ?

# Windows
pip install pygmaps

# Linux/Mac
sudo pip3 install pygmaps

Key Features

The pygmaps library allows you to ?

  • Create interactive maps with custom latitude, longitude, and zoom levels
  • Add grid overlays to display coordinate systems
  • Place colored markers at specific locations
  • Draw circles with defined radius around points
  • Create paths connecting multiple coordinates

Complete Example

Here's a comprehensive example demonstrating all major pygmaps features ?

import pygmaps

# Create a map centered at Hyderabad, India with zoom level 15
mymap = pygmaps.pygmaps(17.45, 78.29, 15)

# Add grid overlay to show coordinate system
mymap.setgrids(17.45, 17.46, 0.001, 78.29, 78.30, 0.001)

# Add a red point marker with tooltip
mymap.addpoint(17.45, 78.29, "#FF0000", "Central Location")

# Add a blue circle with 150-meter radius
mymap.addradpoint(17.45, 78.29, 150, "#0000FF")

# Create a path connecting multiple points
path = [
    (17.45, 78.29),
    (17.55, 78.39), 
    (17.65, 78.49)
]
mymap.addpath(path, "#00FF00")

# Generate the HTML file
mymap.draw('./mymap.html')

print('Map generated successfully!')

Method Breakdown

Method Purpose Key Parameters
pygmaps() Initialize map latitude, longitude, zoom (0-20)
setgrids() Add coordinate grid start/end lat/lng, intervals
addpoint() Place marker lat, lng, color, title
addradpoint() Draw circle lat, lng, radius (meters), color
addpath() Connect points list of coordinates, color
draw() Generate HTML output filename

Color Codes

Use HTML hex color codes for customization ?

  • #FF0000 - Red
  • #0000FF - Blue
  • #00FF00 - Green
  • #FFFF00 - Yellow
  • #FF00FF - Magenta

Troubleshooting

If you encounter a TypeError with addpoint(), ensure you're providing the correct number of parameters. The function expects latitude, longitude, color, and an optional title parameter.

Output

The generated HTML file will display an interactive Google Map with all your custom elements. You can open the HTML file in any web browser to view and interact with your map visualization.

Generated Google Map with markers, paths and circles

Conclusion

Pygmaps provides an easy way to create custom Google Maps with Python. It's ideal for data visualization projects requiring geographic context and interactive map features.

Updated on: 2026-03-25T05:37:42+05:30

584 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements