3

I have a dataframe with locations given as longitude and latitude coordinates (in degrees). Those locations are around New York. Therefore I setup a Basemap in Python that nicely shows all those locations. Works fine!

But: the map is drawn inline and it's very tiny. How can I force that figure to be let's say 3 times larger (zoom=3).

New York area

Here's the code. The data is from the Kaggle Two Sigma Rental Listing challenge.

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

# New York Central Park
# Longitude: -73.968285
# Latitude: 40.785091

m = Basemap(projection='merc',llcrnrlat=40,urcrnrlat=42,\
            llcrnrlon=-75, urcrnrlon=-72, resolution='i', area_thresh=50, lat_0=40.78, lon_0=-73.96)

m.drawmapboundary()
m.drawcoastlines(color='black', linewidth=0.4)
m.drawrivers(color='blue')
m.fillcontinents(color='lightgray')

lons = df['longitude'].values
lats = df['latitude'].values
x,y = m(lons, lats)

# r = red; o = circle marker (see: http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot)
m.plot(x, y, 'ro', markersize=4)

plt.show()
Matthias
  • 5,574
  • 8
  • 61
  • 121

1 Answers1

3

normally it would be as simple as:

plt.figure(figsize=(20,10))

How do you change the size of figures drawn with matplotlib?

but there are some other options too, see:

How to maximize a plt.show() window using Python

also to get the current size (for the purpose of "zoom")

How to get matplotlib figure size

regarding the specific issue:

the figure is inline inside a Jupyter notebook

before creating or plotting the map/figure:

import matplotlib 
matplotlib.rcParams['figure.figsize'] = (30,30) 
Community
  • 1
  • 1
litepresence
  • 3,109
  • 1
  • 27
  • 35
  • Nope, this doesn't work since the figure is inline inside a Jupyter notebook. – Matthias Apr 02 '17 at 13:05
  • hmm maybe `matplotlib.rcParams['figure.figsize']` see: http://stackoverflow.com/questions/36367986/how-to-make-inline-plots-in-jupyter-notebook-larger – litepresence Apr 02 '17 at 13:15
  • 2
    Indeed, setting `import matplotlib as mpl` and then `mpl.rcParams['figure.figsize'] = (30,30)` worked. **Remark:** You need to do that before creating or plotting the map/figure. If you update your answer, I will accept it. – Matthias Apr 02 '17 at 15:43
  • PS: you can do me a favor and try to create a zoomed_inset_axes within the figure showing Manhattan island only. I read a lot of docs, as for example [this one](http://basemaptutorial.readthedocs.io/en/latest/locator.html) but always getting errors. – Matthias Apr 02 '17 at 16:12