ORIGIN

Basemap learning

Python 1 mins186 words

Since I have already introduced Basemap and how to install , I’ll start it directly.

Basic map

First import libraries for drawing maps.

1
2
import matplotlib.pyplot as plot 
from mpl_toolkits.basemap import Basemap

And then create a basemap project.

1
2
3
4
5
map = Basemap(
projection='ortho', # there a many other projections
lat_0 = 0, # latitude
lon_0 = 0 # longitude
)

(for more projections, visit https://matplotlib.org/basemap/users/mapsetup.html)

Draw the map.

1
2
3
4
5
6
7
# draw the outlines of the projection and fill it with color
map.drawmapboundary(fill_color="aqua")
# fill the continents with color
# color stands for continent color, lake_color is the lake color
map.fillcontinents(color="green",lake_color="aqua")
# draw the costlines
map.drawcoastlines()

Show the map.

1
2
plot.savefig('map.png') # save a picture
plot.show() # start a console to draw the map

So the complete code would be this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import matplotlib.pyplot as plot 
from mpl_toolkits.basemap import Basemap

map = Basemap(
projection='ortho',
lat_0 = 0,
lon_0 = 0
)

map.drawmapboundary(fill_color="aqua")
map.fillcontinents(color="green",lake_color="aqua")
map.drawcoastlines()


plot.savefig('test.png')
plot.show()

img

TOP
COMMENT
  • ABOUT
  • |
o_oyao
  The Jigsaw puzzle is incomplete with even one missing piece. And I want to be the last piece to make the puzzle complete.
Like my post?
Default QR Code
made with ❤️ by o_oyao
©o_oyao 2019-2024

|