Inspect Data: Plotting

Learn why exploratory data visualization is so important for any data science project.

The distinctive feature of geospatial analysis is that it can be displayed on a map or globe. To create a map as a static image, we draw on the descriptive analysis from our previous step: the range between maximum and minimum distribution in terms of longitude and latitude. We fill this list into the border variable.

Press + to interact
import pandas as pd
df = pd.read_csv('MoscowMcD.csv')
# We can add several comma-separated values into one list
border =(df.lon.min(),df.lon.max(),df.lat.min(),df.lat.max())
print(border)

Now we know the height and width of the image that includes all the stores.

Plotting spatial data on a map

OpenStreetMap (OSM) is an international project to create a free map of the world. With this tool, we can find out where on the map the coordinates are placed. To find out, open OpenStreetMap and enter the border coordinates from above as a bounding box. Click the “Export” button in the top left corner to get there. The bounding box is the area defined by four points, which includes all of the spatial stores. After that, we’ll receive a map section that includes the coordinates we just entered.

Press + to interact
OpenStreetMap: Map of Moscow
OpenStreetMap: Map of Moscow

We can see for the first time which place is behind the longitude and latitude data: it’s the Moscow metropolitan area.

To export this image, proceed as follows:

Click the “Share” button on the right pane and download the image in the desired format, e.g., as a .png file.

We can use this extract of the map view of Moscow to map the coordinates to it using matplotlib. Draw the coordinates as scatter points in the map image area. Note that it’s important to set up the x-axis, xlim, and the y-axis, ...