 # Basemap: Removing white space in savefig

Hello,

I am plotting a fig in Basemap, but I don’t need the extra while space on the sides of the figure when I use savfig(). I tried axes([0,0,1,1]) but that just gave me a blank white screen with some ticks on the sides. Is there another way to do it with Basemap? Please help!

Thank you,

George B.

George: If you want to preserve the aspect ratio of the map, you need to calculate it ahead of time and make sure that you create a figure with the same aspect ratio and define an axes with no white space. For example, for a global cylindrical equidistant projection, the aspect ration should be 2:1, so you would create a figure like this

from mpl_toolkits.basemap import Basemap

import matplotlib.pyplot as plt

import numpy as np

fig = plt.figure(figsize=(10,5))

ax = plt.axes([0,0,1,1])

m = Basemap(projection=‘cyl’,lon_0=180)

m.drawcoastlines()

m.fillcontinents()

m.drawparallels(np.arange(-60,61,30))

m.drawmeridians(np.arange(60,301,60))

plt.savefig(‘nowhite.png’)

plt.show()

Note that you need to create the axes instance before the Basemap instance.

If you don’t care about the aspect ratio of the map being correct, you can set fix_aspect=‘False’, create a map of any size you like, and use an axes with no white space. For example,

from mpl_toolkits.basemap import Basemap

import matplotlib.pyplot as plt

import numpy as np

fig = plt.figure(figsize=(8,8))

ax = plt.axes([0,0,1,1])

m = Basemap(projection=‘cyl’,lon_0=180,fix_aspect=False)

m.drawcoastlines()

m.fillcontinents()

m.drawparallels(np.arange(-60,61,30))

m.drawmeridians(np.arange(60,301,60))

plt.savefig(‘nowhite2.png’)

plt.show()

If you don’t set fix_aspect=False in this example, you’ll get a map with a 2:1 aspect ratio and lots of white space on the top and bottom of the plot.

-Jeff

``````
<details class='elided'>
<summary title='Show trimmed content'>&#183;&#183;&#183;</summary>

On Tue, 10 Nov 2009 13:13 -0500, "George Bonev" <georgebg8@...287...> wrote:

> Hello,
>
>
>
> I am plotting a fig in Basemap, but I don't need the extra while space on the sides of the figure when I use savfig(). I tried axes([0,0,1,1]) but that just gave me a blank white screen with some ticks on the sides. Is there another way to do it with Basemap? Please help!
>
>
>
> Thank you,
>
>
>
> George B.

------
Jeffrey S. Whitaker
Phone: (303)497-6313
FAX: (303)497-6449
NOAA/OAR/CDC R/CDC1 325 Broadway, Boulder, CO, USA 80305-3328 http://www.cdc.noaa.gov/people/jeffrey.s.whitaker
``````