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()

1 Answer 1

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) 
Sign up to request clarification or add additional context in comments.

4 Comments

Nope, this doesn't work since the figure is inline inside a Jupyter notebook.
hmm maybe matplotlib.rcParams['figure.figsize'] see: stackoverflow.com/questions/36367986/…
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.
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 but always getting errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.