Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble with basemap subplots

I need to make a plot with n number of basemap subplots. But when I am doing this the all the values are plotted on the first subplot.

My data is a set of 'n' matrixes, stored in data_all.

f, map = plt.subplots(n,sharex=True, sharey=True, figsize=(20,17))

plt.subplots_adjust(left=None, bottom=None, right=None, top=None,
                    wspace=None, hspace=0.)

for i in range(n):
    map = Basemap(projection='merc', lat_0=0, lon_0=180,
                  resolution='h', area_thresh=0.1,
                  llcrnrlon=0, llcrnrlat=-45,
                  urcrnrlon=360, urcrnrlat=45)
    map.drawcoastlines(linewidth=0.5)
    map.drawmapboundary()
    map.drawmapboundary()
    nx = data_all.shape[0]
    ny = data_all.shape[1]
    lon, lat = map.makegrid(ny[i], nx[i])
    z,y = map(lon, lat)
    cs = map.contourf(z, y, data_all[i])
like image 612
Nidhi Avatar asked Jun 24 '13 01:06

Nidhi


2 Answers

I can't test it at the moment, but basically, you just need to tell basemap which axes to use.

For example:

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

fig, axes = plt.subplots(nrows=4, ncols=3)
for ax in axes.flat:
    map_ax = Basemap(ax=ax)
    map_ax.drawcoastlines()
plt.show()

enter image description here

like image 146
Joe Kington Avatar answered Nov 15 '22 14:11

Joe Kington


Hope this will help you. https://github.com/matplotlib/basemap/blob/master/examples/panelplot.py It shows how to make multi-panel plots.

like image 27
mitchelllc Avatar answered Nov 15 '22 15:11

mitchelllc