This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib2 import urlopen | |
from pylab import imshow, imread, show | |
lon = [49.5,50.35] | |
lat = [18.6,20.2] | |
scale = 700000 | |
# open an openstreetmap export png file via http | |
url = urlopen('http://parent.tile.openstreetmap.org/cgi-bin/export?' | |
'bbox={lat1:.2f},{lon1:.2f},{lat2:.2f},{lon2:.2f}&' | |
'scale={scale:d}&format=png'.format(lat1=lat[0], | |
lat2=lat[1], | |
lon1=lon[0], | |
lon2=lon[1], | |
scale=scale)) | |
# plot the map | |
imshow(imread(url), extent=lat+lon, aspect='equal') | |
# plot other data here | |
show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib2 import urlopen | |
from pylab import imshow, imread, show | |
lon = [49.5,50.35] | |
lat = [18.6,20.2] | |
scale = 700000 | |
print "Downloading map... " | |
tries = 0 | |
url = None | |
while tries < 60: | |
tries += 1 | |
print 'Try {}...'.format(tries) | |
try: | |
url = urlopen('http://parent.tile.openstreetmap.org/cgi-bin/export?' | |
'bbox={lat1:.2f},{lon1:.2f},{lat2:.2f},{lon2:.2f}&' | |
'scale={scale:d}&format=png'.format(lat1=lat[0], | |
lat2=lat[1], | |
lon1=lon[0], | |
lon2=lon[1], | |
scale=scale)) | |
except HTTPError: | |
sleep(5) | |
continue | |
else: | |
print 'Map successfully downloaded.' | |
break | |
if url is None: | |
print 'Failed to download a map.' | |
else: | |
m = imread(url) | |
imshow(m, extent=lat+lon, aspect='equal') | |
show() |
By the way: hexbin has an amazing parameter C (lacking in every other density plot function I've encountered). According to documentation:
If C is specified, it specifies values at the coordinate (x[i],y[i]). These values are accumulated for each hexagonal bin and then reduced according to reduce_C_function, which defaults to numpy’s mean function (np.mean).My data is counts (of Geiger-Mueller counter) per minute versus geographic position. I want to plot an average counts per minute value in each bin, not total, as other systems I've tried would have me do. Some would even limit me to number of data entries.
Brak komentarzy:
Prześlij komentarz