Answers for "draw a marker in basemap python"

0

draw a marker in basemap python

import matplotlib.pyplot as plt
import numpy
from mpl_toolkits.basemap import Basemap

# 1. get data 
lon = [-122.2416355, -122.2977475, -121.204408, -118.3272612, -119.0194639]
lat = [37.7652076, 37.88687, 40.2362738, 33.34221, 35.3738712]
crowd = [8.0, 500.0, 4.0, 44.0, 119.0]

# 2. draw map 

map = Basemap(projection='lcc', resolution='h', 
            lat_0=37.5, lon_0=-119,
            width=1E6, height=1.2E6) 

map.drawcoastlines()
map.drawcountries()
map.drawstates()
map.fillcontinents()
map.drawmapboundary()
x,y = map(lon, lat)   # convert (long-lat) degrees to map coords

for x1, y1, c in zip(x, y, crowd):
    # markersize is scale down by /10
    # need alpha<1 to get some transparency
    # red color is more appropriate
    map.plot(x1, y1, 'ro', markersize=c/10., alpha=0.4)

plt.show()
Posted by: Guest on October-12-2020

Python Answers by Framework

Browse Popular Code Answers by Language