Visualization of map information with Plotly + Mapbox
In many fields, there is a need to use geographic information in daily operations. Many industries such as aviation, transportation, real estate, civil engineering, shipping, researchers, and consulting use GIS. In these industries, GIS has become an essential infrastructure for visualizing geographic information to understand spatial location and for analysis, forecasting, and planning.
In this article, I will introduce how to visualize map information using Mapbox, which is supported in Python within the Plotly library for visualizing geographical information. I will instroduce how to visualize base geographic map with Plotly + Mapbox.
0.Preprocess
At first, you have to install Plotly in your Python environment if you haven’t already installed it. You can install Plotly as below for simplely.
pip install plotly
- Visualize base map
You can plot geographic map easily as below.
import plotly.graph_objects as gofig = go.Figure()
fig.add_trace(go.Scattermapbox())
fig.update_layout(margin ={'l':0,'t':0,'b':0,'r':0},
mapbox = {
'center': {'lon': 139, 'lat': 36.5},
'style': "stamen-terrain",
'zoom': 4.5},
width=1600,
height=900,)
fig.show()
Now, I visualized the geographic map around Japan.
a. Define graph object instancefig
as plotly.graph_objects.Figure()
.
b. Add graph object to instance fig
with fig.add_trace()
. Here, I added plotly.graph_objects.Scattermapbox()
. This the Mapbox object which is supported within Plotly. With using this object, we can use Mapbox’s geographic map.
c. Adjust map parameters with fig.update_layout()
. I added 4 parameters in this object, margin
, mapbox
, width
, height
. margin
means that the margin size of the graph area. mapbox
parameter can set the ‘center’(center coodinate position), ‘style’(map design style), ‘zoom’(zoom size value).
And, this figure can be saved as .html
, then you can see map interactively like adjusting zoom ratio. You can check the interactive figure at the link of below figure.
These are the base settings of first visualizing map with Plotly + Mapbox. Wirh only changing these parameters, you can customize forwhat you want. Next, I will show the variation with only using these settings.
2. Customize map
‘center’: {‘lon’: 118, ‘lat’: 18},
‘center’: {‘lon’: 70, ‘lat’: 18},
‘center’: {‘lon’: 15, ‘lat’: 46},
‘center’: {‘lon’: 15, ‘lat’: 5},
‘center’: {‘lon’: -100, ‘lat’: 40},
‘center’: {‘lon’: -60, ‘lat’: -10},
'style': "open-street-map",
'style': "carto-positron",
'style': "carto-darkmatter",
'style': "stamen-toner",
'style': "stamen-watercolor",
'zoom': 3
'zoom': 6
In the future, I will introduce the methods how to plot information and actual data on map.