3

TL; DR

How to I set the map to be exactly 1600x900 px?

Description

I am trying to draw a map with Jupyter Notebook using Basemap library as follows:

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

atlas = Basemap(
    llcrnrlon  =   -10.5, # Longitude lower right corner
    llcrnrlat  =      35, # Latitude lower right corner
    urcrnrlon  =    14.0, # Longitude upper right corner
    urcrnrlat  =    44.0, # Latitude upper right corner
    resolution =     'i', # Crude resolution
    projection = 'tmerc', # Transverse Mercator projection
    lat_0      =    39.5, # Central latitude
    lon_0      =   -3.25  # Central longitude
)

atlas.drawmapboundary(fill_color='aqua')
atlas.fillcontinents(color='#cc9955',lake_color='aqua')
atlas.drawcoastlines()
plt.show()

and getting the following result

enter image description here

Is it possible to make the drawn map larger, defining the minimum width and height it should have?

6
  • Would adjusting the figure size do what you want?(Making sure I understand the question properly) Commented Dec 23, 2017 at 11:22
  • I would like to produce a map that is 1600x900 px passing the dimensions to the constructor, for example, or calling a Basemap method. Commented Dec 23, 2017 at 11:25
  • Can you be more specific? Do you want to create an image of size 1600x900 pixels? Do you want the map to be 1600x900 pixels? Do you want this to be the saved image or the one shown in the notebook? (In the latter case mind that usually the notebook is less than 1600 pixels wide, are you hence asking for a solution to make the notebook wider?) Note that you can always make the figure much larger, e.g. plt.figure(figsize=(20, 15)) and the image will be scaled down to whatever fits into the notebook. Commented Dec 23, 2017 at 12:41
  • @ImportanceOfBeingErnest I want the map to be 1600x900 px Commented Dec 23, 2017 at 14:24
  • I don't think that is clear enough, given the other questions in my previous comment. But since you already accepted an answer, which does not show how to create a map of given size, the requirement does not seem to be that strict. Commented Dec 23, 2017 at 14:28

1 Answer 1

4

You can use figure.

For example:

plt.figure(figsize=(1, 1)) 

Creates an inch-by-inch image, which will be 80-by-80 pixels unless you also give a different dpi argument. You can change dpi with two possible ways

Way 1: Passing it as an argument to the figure as the following:(i.e 300)

plt.figure(figsize=(1, 1),dpi=300)

Way 2:Passing it to savefig()

plt.savefig("foo.png", dpi=300)

Perfect Example

Sign up to request clarification or add additional context in comments.

2 Comments

How do I change the map dpi?
I have added possible ways to the answer. Hopefully, that helps.

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.