Inspect Data: Plotting
Learn why exploratory data visualization is so important for any data science project.
We'll cover the following...
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.
import pandas as pddf = pd.read_csv('MoscowMcD.csv')# We can add several comma-separated values into one listborder =(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.
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, ...