Easily draw a map with matplotlib.basemap

basemap: Easily plot a map in python. It is very useful when you want to visualize the data on a map.

CMtYKZoWsAAWiC0-2.png

Installation. It's been a hassle, but it's now much easier!

@mac


$ brew install geos
#$ pip install Pillow html5lib BeautifulSoup4
$ wget https://jaist.dl.sourceforge.net/project/matplotlib/matplotlib-toolkits/basemap-1.0.7/basemap-1.0.7.tar.gz
$ tar zxvf basemap-1.0.7.tar.gz
$ cd basemap-1.0.7
$ python setup.py install

Example: Labeled map

map.py


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

fig = plt.figure(figsize=(8,4))
m = Basemap(projection='merc',
                 resolution='h',
                 llcrnrlon=131,
                 llcrnrlat=33,
                 urcrnrlon=141,
                 urcrnrlat=38)

m.drawcoastlines(color='lightgray')
m.drawcountries(color='lightgray')
m.fillcontinents(color='white', lake_color='#eeeeee');
m.drawmapboundary(fill_color='#eeeeee')
#m.drawparallels(np.arange(31.0, 38.1, 1.0), labels = [1,0,0,0], fontsize=12)
#m.drawmeridians(np.arange(132.0, 140.1, 2.0), labels = [0,0,0,1], fontsize=12)
  
sumoto_lon = 134.7687
sumoto_lat = 34.3755
hiratsuka_lon = 139.3581
hiratsuka_lat = 35.3587

x1,y1 = m(sumoto_lon, sumoto_lat)
x2,y2 = m(hiratsuka_lon, hiratsuka_lat)
m.plot(x1, y1, 'm.', markersize=10)
m.plot(x2, y2, 'm.', markersize=10)
plt.text(x1 + 10000, y1 + 10000, u"sumoto")
plt.text(x2 + 10000, y2 + 10000, u"hiratsuka")

plt.show()
fig.savefig('map.png')

map.png

Recommended Posts

Easily draw a map with matplotlib.basemap
Draw a graph with NetworkX
Draw a graph with networkx
Easily cProfile with a decorator
I tried to draw a route map with Python
Draw a graph with Julia + PyQtGraph (2)
Draw a loose graph with matplotlib
Draw a beautiful circle with numpy
Draw a graph with Julia + PyQtGraph (1)
Draw a graph with Julia + PyQtGraph (3)
Draw a graph with pandas + XlsxWriter
Draw a graph with PySimple GUI
Easily build a development environment with Laragon
Draw a heart in Ruby with PyCall
Map rent information on a map with python
Draw a Mandelbrot set with Brainf * ck
I made a Hex map with Python
Try drawing a map with python + cartopy 0.18.0
Draw a graph with PyQtGraph Part 1-Drawing
I made a plug-in "EZPrinter" that easily outputs map PDF with QGIS.
Draw a flat surface with a matplotlib 3d graph
Draw a graph with Japanese labels in Jupyter
How to draw a 2-axis graph with pyplot
Draw a graph with PyQtGraph Part 3-PlotWidget settings
Draw a graph by processing with Pandas groupby
Try to draw a life curve with python
You can easily create a GUI with Python
[Python] Draw a Mickey Mouse with Turtle [Beginner]
Folium: Visualize data on a map with Python
Draw a graph with PyQtGraph Part 4-PlotItem settings
Draw a graph with matplotlib from a csv file
Draw a graph with PyQtGraph Part 6-Displaying a legend
Create a Python console application easily with Click
Try drawing a map with Python's folium package
Visualize grib2 on a map with python (matplotlib)
Draw a graph with PyQtGraph Part 5-Increase the Y-axis
[Python] Draw a Qiita tag relationship diagram with NetworkX
Easily daemonized with Supervisor
A4 size with python-pptx
Why not create a stylish table easily with Python?
Forcibly draw something like a flowchart with Python, matplotlib
Easily beep with python
Draw a graph with PyQtGraph Part 2--Detailed plot settings
[Python] How to draw a scatter plot with Matplotlib
Study math with Python: Draw a sympy (scipy) graph with matplotlib
Tornado-Let's create a Web API that easily returns JSON with JSON
[Visualization] I want to draw a beautiful graph with Plotly
Draw Bezier curves with Go
Learn librosa with a tutorial 1
Easily serverless with Python with chalice
Try programming with a shell!
Draw netCDF file with python
Easily write if-elif with lambda
Create a homepage with django
Let's draw a logistic function
Using a printer with Debian 10
Make a fortune with Python
Create patent map with Streamlit
Easily build CNN with Keras
Create a heatmap with pyqtgraph
Draw a heart in Python