Hi,
I'm developing a websuite for open meshed networks written in django. I
must admit, matplotlib and such was kinda hard stuff to step into. Most
examples and documentation is only based on the pylab api, which isn't
well suited for my purpos, because Django runs best with mod-python.
Anyways. I'm wrote a function which generates tiles for google maps and
those should be overlayers with transparent background.
My code currently looks like this:
from matplotlib.toolkits.basemap import Basemap
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
[...]
def mktopo(ll_lng, ll_lat, ur_lng, ur_lat, aspect, filename, state):
"""Generates atopo tile for given latitude/longitude pairs"""
dpi = 64
fig = Figure()
canvas = FigureCanvas(fig)
# what does this do ???
#fig.set_facecolor((1.0,1.0,0,0.0))
m =
Basemap(llcrnrlon=ll_lng,llcrnrlat=ll_lat,urcrnrlon=ur_lng,urcrnrlat=ur_lat,
resolution='c',area_thresh=1000.,projection='merc',lat_ts=-8.0)
m.ax = fig.add_axes([0, 0, 1, 1], axisbg=(1.0,1.0,0.0,0.0),
frameon=False )
# 72 dpi
# we need 256x256 pixel images
fig.set_figsize_inches(256/dpi, 256/dpi)
nodes = Node.objects.exclude(gps_position_lat=False)
lats=[]
lons=[]
for node in nodes:
lons.append(node.gps_position_lng)
lats.append(node.gps_position_lat)
#print node
#a = m(node.gps_position_lat,node.gps_position_lng)
#print a
x,y = m(lons,lats)
m.plot(x,y,'bo')
canvas.print_figure(filename, dpi=dpi)
kindly regards
Daniel