本文整理汇总了Python中mpl_toolkits.basemap.Basemap.plot方法的典型用法代码示例。如果您正苦于以下问题:Python Basemap.plot方法的具体用法?Python Basemap.plot怎么用?Python Basemap.plot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpl_toolkits.basemap.Basemap
的用法示例。
在下文中一共展示了Basemap.plot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lambert_conformal
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
def lambert_conformal(request):
import matplotlib
from mpl_toolkits.basemap import Basemap
import numpy as np
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
width = float(request.GET.get('width', 6000000))
height = float(request.GET.get('height', 4500000))
lat = float(request.GET.get('lat',-7))
lon = float(request.GET.get('lon',107))
true_lat1 = float(request.GET.get('true_lat1',5))
true_lat2 = float(request.GET.get('true_lat2',5))
m = Basemap(width=width,height=height,
rsphere=(6378137.00,6356752.3142),\
resolution=None,projection='lcc',\
lat_1=true_lat1,lat_2=true_lat2,lat_0=lat,lon_0=lon)
fig = Figure()
canvas = FigureCanvas(fig)
m.ax = fig.add_axes([0, 0, 1, 1])
m.drawlsmask(land_color='gray',ocean_color='white',lakes=True)
m.drawparallels(np.arange(-90.,91.,30.), color='black')
m.drawmeridians(np.arange(-180.,181.,60.), color='black')
x, y = m(lon, lat)
m.plot(x, y, 'ro')
response = HttpResponse(content_type='image/png')
canvas.print_figure(response, dpi=100)
return response
示例2: plot_us
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
def plot_us(lats, lons, save_name=None):
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111)
big_map = Basemap(resolution='h',
lat_0=36, lon_0=-107.5,
llcrnrlat=32, llcrnrlon=-125,
urcrnrlat=43, urcrnrlon=-110)
big_map.drawcoastlines()
big_map.drawstates()
big_map.drawcountries()
big_map.drawmapboundary(fill_color='#7777ff')
big_map.fillcontinents(color='#ddaa66', lake_color='#7777ff', zorder=0)
x, y = big_map(lons, lats)
big_map.plot(x[0], y[0], 'ro', markersize=2)
axins = zoomed_inset_axes(ax, 20, loc=1)
ll_lat, ll_lon = 37.8, -122.78
ur_lat, ur_lon = 38.08, -122.43
axins.set_xlim(ll_lon, ur_lon)
axins.set_ylim(ur_lon, ur_lat)
small_map = Basemap(resolution='h',
llcrnrlat=ll_lat, llcrnrlon=ll_lon,
urcrnrlat=ur_lat, urcrnrlon=ur_lon,
ax=axins)
small_map.drawcoastlines()
small_map.drawmapboundary(fill_color='#7777ff')
small_map.fillcontinents(color='#ddaa66', lake_color='#7777ff', zorder=0)
x, y = small_map(lons, lats)
small_map.plot(x, y, 'ro', markersize=3)
mark_inset(ax, axins, loc1=2, loc2=4, fc="none", ec="0.5")
if save_name:
fig.savefig(save_name)
示例3: mapTut
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
def mapTut():
m = Basemap(projection='mill',llcrnrlat=20,urcrnrlat=50,\
llcrnrlon=-130,urcrnrlon=-60,resolution='c')
m.drawcoastlines()
m.drawcountries()
m.drawstates()
m.fillcontinents(color='#04BAE3',lake_color='#FFFFFF')
m.drawmapboundary(fill_color='#FFFFFF')
# Houston, Texas
lat,lon = 29.7630556,-95.3630556
x,y = m(lon,lat)
m.plot(x,y, 'ro')
lon, lat = -104.237, 40.125 # Location of Boulder
xpt,ypt = m(lon,lat)
m.plot(xpt,ypt, 'go')
plt.title("Geo Plotting")
plt.show()
示例4: __init__
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
class Mapper:
def __init__(self, state):
with open(state_boundries_file_loc) as f:
for line in f:
line = line.rstrip().split(',')
if line[0].lower() == state.lower():
ur_lon, ll_lat = float(line[1]), float(line[3])
ll_lon, ur_lat = float(line[2]), float(line[4])
center_lon = ll_lon + ur_lon
if math.copysign(1, ll_lon) != math.copysign(1, ur_lon):
center_lon = -180 + center_lon
else:
center_lon = center_lon / 2
center_lat = (ll_lat + ur_lat) / 2
self.m = Basemap(llcrnrlon = ll_lon, llcrnrlat = ll_lat,
urcrnrlon = ur_lon, urcrnrlat = ur_lat,
projection = 'lcc', lat_1 = center_lat,
lon_0 = center_lon)
def setBorders(self):
self.m.readshapefile(states_shapefile_loc,
'states', drawbounds = True)
def plotPoint(self, lat, lon):
self.m.plot(lat, lon, latlon=True, marker='o', color='m')
def displayMap(self):
plt.show()
示例5: drawNPole
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
def drawNPole(self):
#No es muy ortodoxo dibujar dentro de la clase
my_map = Basemap(projection='npstere',boundinglat=50,lon_0=270,resolution='h', round=True)
my_map.drawcoastlines()
my_map.drawcountries()
my_map.fillcontinents(color='coral')
my_map.drawmapboundary()
#print "tamano:", len(self)
for measure in self:
x,y = my_map(measure.getLon(), measure.getLat())
print measure.getLat(), measure.getLon(), measure.getSic()
color = 'go'
#print "color->", measure.getSic()
if measure.getSic()>0 and measure.getSic()<=0.2:
color = 'go'
elif measure.getSic()>0.2 and measure.getSic()<=0.5:
color = 'yo'
else:
color = 'ro'
my_map.plot(y, x, color, markersize=12)
my_map.drawmeridians(np.arange(0, 360, 30))
my_map.drawparallels(np.arange(-90, 90, 30))
#m.hexbin(x1,y1, C=sic[beam],gridsize=len(sic[beam]),cmap=plt.cm.jet)
plt.gcf().set_size_inches(18,10)
plt.show()
示例6: __init__
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
class Map:
def __init__(self, boundary=[[24.527135, -127.792969], [49.61071, -59.765625]], default=True):
from mpl_toolkits.basemap import Basemap
minLat, minLon, maxLat, maxLon = [item for t in boundary for item in t]
self.m = Basemap(
llcrnrlon=minLon,
llcrnrlat=minLat,
urcrnrlon=maxLon,
urcrnrlat=maxLat,
resolution="l",
projection="merc",
area_thresh=1000000,
lon_0=minLon + (maxLon - minLon) / 2,
lat_0=minLat + (maxLat - minLat) / 2,
)
if default:
self.configure()
def configure(self):
self.m.drawcoastlines(linewidth=1.0)
self.m.drawcountries(linewidth=1.0)
self.m.fillcontinents(color="#FFFFFF", lake_color="#FFFFFF")
self.m.drawstates(linewidth=0.5)
self.m.drawmapboundary(fill_color="#FFFFFF")
def plotPoints(self, longitude, latitudes, color, lw=0, marker="o", *args, **kwargs):
mlon, mlat = self.m(longitude, latitudes)
self.m.plot(mlon, mlat, color=color, lw=lw, marker=marker, *args, **kwargs)
示例7: main
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
def main():
data = numpy.genfromtxt("data.csv", dtype=None, delimiter=',', names=True)
#lat - data[x][1]
#lon - data[x][2]
print(data)
# Note that we're drawing on a regular matplotlib figure, so we set the
# figure size just like we would any other.
plt.figure(figsize=(28,18))
# Create the Basemap
event_map = Basemap(projection='merc',
resolution='l', area_thresh=1000.0, # Low resolution
lat_0 = 55.0, lon_0=60.0, # Map center
llcrnrlon=-179, llcrnrlat=-72, # Lower left corner
urcrnrlon=179, urcrnrlat=78) # Upper right corner
# Draw important features
event_map.drawcoastlines()
event_map.drawcountries()
event_map.fillcontinents(color='0.8') # Light gray
event_map.drawmapboundary()
a = [f for f in data if int(f[2])<500]
b = [f for f in data if int(f[2])<500]
# Draw the points on the map:
for i in range(len(data)-8000):
x, y = event_map(data[i][2], data[i][1]) # Convert lat, long to y,x
marker_size = data[i][3]/4
event_map.plot(x,y, 'ro', markersize=marker_size, alpha=0.3)
plt.savefig('map.png', bbox_inches='tight')
示例8: show_route
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
def show_route(self):
'''
Display the route coordinates on a map of Tompkins County
'''
# plot basemap w/ state and county lines, etc
fig = plt.figure()
m = Basemap(llcrnrlon=-76.8, llcrnrlat=42.2, urcrnrlon=-76.2, \
urcrnrlat=42.7, rsphere=(6378137.00,6356752.3142), resolution='l', \
projection='merc')
m.shadedrelief()
m.drawcoastlines()
m.drawstates()
m.drawcountries()
m.drawcounties()
# plot ny state water features
m.readshapefile('data\\water\\NHD_M_36_New_York_ST\\NHDFlowline','water', color='LightSteelBlue', linewidth=2.)
m.readshapefile('data\\water\\NHD_M_36_New_York_ST\\NHDArea','water_area', drawbounds=False)
m.readshapefile('data\\water\\NHD_M_36_New_York_ST\\NHDWaterbody','lakes', drawbounds=False)
for lake in m.lakes + m.water_area:
poly = Polygon(lake, facecolor='LightSteelBlue', edgecolor='CornflowerBlue')
plt.gca().add_patch(poly)
# read and plot tompkins county shapefile
m.readshapefile('data\\parcels\\ParcelPublic2016_WGS84', 'parcels')
# plot route coordinates
m.plot(self.coordinates[:,0], self.coordinates[:,1], '.-',
latlon=True, c='FireBrick', lw=2.)
# finalize and show plot
fig.show()
示例9: plot
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
def plot(mp):
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
map = Basemap(projection='mill', llcrnrlon=0,llcrnrlat=-90,urcrnrlon=360,urcrnrlat=90)
map.drawcoastlines(linewidth=0.25)
map.drawmeridians(numpy.arange(0,360,30))
map.drawparallels(numpy.arange(-90,90,30))
data = mp.data
lons, lats = map.makegrid(mp.width, mp.height)
x, y = map(*numpy.meshgrid(mp.longitudes, mp.latitudes))
#clevs = range(200, 325, 5)
clevs = list(frange(0, 8, 0.25))
cs = map.contourf(x, y, data, clevs, cmap=plt.cm.jet)
cbar = map.colorbar(cs, location='bottom', pad="5%")
cbar.set_label('K')
lon, lat = 174.7772, -41.2889
xpt,ypt = map(lon,lat)
map.plot(xpt,ypt,'bo')
plt.title(mp.name)
plt.gcf().set_size_inches(10,10)
plt.savefig(mp.name + '.png',dpi=100)
示例10: __init__
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
class MapDrawer:
mymap = None;
projection = 'hammer';
def __init__(self, projection = 'hammer', lon_0 = 0, resolution = 'c'):
self.mymap = Basemap(projection, lon_0, resolution);
self.mymap.bluemarble()
def show_map(self):
self.mymap.show();
def draw_markers(self, lats, longs, title = '', clever_mode = 0):
# draw parallels and meridians.
lats = np.array(lats)
longs = np.array(longs)
if clever_mode:
print "Clever mode is under construction"
xpt,ypt = self.mymap(longs,lats)
print xpt;
self.mymap.plot(xpt, ypt, 'ro')
if title:
plt.title('Tweets about ' + title)
plt.show()
#mymap = Basemap(projection = 'hammer', lon_0 = 0, resolution = 'c');
#xpt,ypt = mymap(longs,lats)
#mymap.plot(xpt, ypt, 'ro')
示例11: plot_region_pnw
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
def plot_region_pnw(data,lat_coord,lon_coord,lat_nw,lat_se,lon_nw,lon_se,title,varfrac):
plt.clf()
circles=[30,40,50,60,70]
meridians=[-130,-120,-110]
ny,nx=lat_coord.shape
m = Basemap(projection='stere',lon_0=lon_coord[ny/2,nx/2],lat_0=lat_coord[ny/2,nx/2],resolution='l',llcrnrlon=lon_coord[-1,0],llcrnrlat=lat_coord[-1,0],urcrnrlon=lon_coord[0,-1],urcrnrlat=lat_coord[0,-1])
x,y=m(lon_coord[:],lat_coord[:])
plt.title('Plotting data for: '+title+'\nvariance:'+str(varfrac))
try:
max=np.absolute(data[lat_nw:lat_se,lon_nw:lon_se]).max()
m.pcolor(x[lat_nw:lat_se,lon_nw:lon_se],y[lat_nw:lat_se,lon_nw:lon_se],data[lat_nw:lat_se,lon_nw:lon_se],vmin=-max,vmax=max)
plt.colorbar()
except:
raise
m.plot(x[lat_nw:lat_se,lon_nw:lon_se],y[lat_nw:lat_se,lon_nw:lon_se],'r.') # Just put a dot at the x y point
m.drawcoastlines()
m.drawcountries()
y=m.drawstates()
m.drawparallels(circles)
m.drawmeridians(meridians)
try:
os.remove(output_dir+'/._'+title+'.png')
except:
pass
plt.savefig(output_dir+'/'+title+'.png')
示例12: map_sites_inset
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
def map_sites_inset(datasets, data_dir='./data/', focal_sites=[], markers = ['o'],
colors=['b', 'r', 'g', 'y', 'c'], markersizes=4):
"""Generate a US map with sites color-coded by database"""
from mpl_toolkits.basemap import Basemap
map = Basemap(projection='merc',llcrnrlat=24.5,urcrnrlat=49,\
llcrnrlon=-125,urcrnrlon=-69,lat_ts=50,resolution='l')
map.drawcoastlines(linewidth=1.5)
map.drawcountries(linewidth=1.5)
map.drawmapboundary()
for i, dataset in enumerate(datasets):
latlong_data = import_latlong_data(data_dir + dataset + '_lat_long.csv')
lats = latlong_data["lat"]
longs = latlong_data["long"]
x,y = map(longs,lats)
map.plot(x,y, ls = '', marker = markers[i], markerfacecolor = colors[i],
markeredgewidth = 0.25, markersize = markersizes)
if len(focal_sites) > 0:
focal_x, focal_y = map(focal_sites[1], focal_sites[0])
map.plot(focal_x, focal_y, ls = '', marker='o', markeredgecolor='k',
markerfacecolor='w', markeredgewidth=4, markersize=50)
plt.savefig('map_of_sites_US.png', dpi=320, bbox_inches = 'tight', pad_inches=0)
示例13: plot_clinic_locations
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
def plot_clinic_locations():
fig = plt.figure(figsize=(20,10))
# define the map
m = Basemap(llcrnrlon=-145.5,llcrnrlat=1.,urcrnrlon=-2.566,urcrnrlat=46.352,\
rsphere=(6378137.00,6356752.3142),\
resolution='l',area_thresh=1000.,projection='lcc',\
lat_1=50.,lon_0=-107.)
# # Draw the coastlines on the map
m.drawcoastlines()
# # Draw country borders on the map
m.drawcountries()
# Fill the land with grey
m.fillcontinents(color = '#888888', zorder=0)
# Draw the map boundaries
m.drawmapboundary(fill_color='#f4f4f4')
# Define our longitude and latitude points
# We have to use .values because of a wierd bug when passing pandas data
# to basemap.
#x,y = m(cities['lng'].values, cities['lat'].values)
# Plot them using round red markers of size 6
for lat in data.latitude:
lon = data.longitude[data.latitude==lat].iloc[0]
x,y = m(lon, lat)
m.plot(x, y, marker='o', color='r', markersize=6)
# Show the map
plt.show()
示例14: create_png
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
def create_png(url, outfile):
quakes = get_earthquake_data('http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.csv')
print(quakes[0].__dict__)
# Set up Basemap
mpl.rcParams['figure.figsize'] = '16, 12'
m = Basemap(projection='kav7', lon_0=-90, resolution = 'l', area_thresh = 1000.0)
m.drawcoastlines()
m.drawcountries()
m.drawmapboundary(fill_color='0.3')
m.drawparallels(np.arange(-90.,99.,30.))
junk = m.drawmeridians(np.arange(-180.,180.,60.))
# sort earthquakes by magnitude so that weaker earthquakes
# are plotted after (i.e. on top of) stronger ones
# the stronger quakes have bigger circles, so we'll see both
start_day = quakes[-1].timestamp[:10]
end_day = quakes[0].timestamp[:10]
quakes.sort(key=lambda q: q.magnitude, reverse=True)
# add earthquake info to the plot
for q in quakes:
x,y = m(q.lon, q.lat)
mcolor, msize = get_marker(q.magnitude)
m.plot(x, y, mcolor, markersize=msize)
# add a title
plt.title("Earthquakes {0} to {1}".format(start_day, end_day))
plt.savefig(outfile)
示例15: plot_quakes
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import plot [as 别名]
def plot_quakes(quakes):
ll_lon, ll_lat, ur_lon, ur_lat = find_left_most(quakes)
print ll_lon
print ll_lat
print ur_lon
print ur_lat
m = Basemap(llcrnrlon=ll_lon,llcrnrlat=ll_lat,
urcrnrlon=ur_lon,urcrnrlat=ur_lat,
resolution='l',area_thresh=1000.,projection='merc',
lat_0=62.9540,lon_0=-149.2697)
m.drawcoastlines()
m.drawcountries()
m.fillcontinents(color='coral',lake_color='blue')
m.drawmapboundary(fill_color='aqua')
mags = quakes.Mag
lons = quakes.Lon
lats = quakes.Lat
x, y = m(quakes.Lon, quakes.Lat)
#Documentation from http://matplotlib.org/basemap/api/basemap_api.html#mpl_toolkits.basemap.Basemap.plot
#Additional hints from http://stackoverflow.com/questions/8409095/matplotlib-set-markers-for-individual-points-on-a-line
for key in x.keys(): #Note that an entry's data in the series share the same key.
m.plot(x[key], y[key], marker='o', markersize=mags[key]*4, color='b', alpha = 0.5)
#alpha is transparency
#color is blue
#marker size is magnitude * 4
#marker is circular shaped
#x, y = m(quakes.Lon, quakes.Lat)
#m.plot(x, y, 'k.')
return m