How to create Geographical Maps and Graphs in Python

Last updated on Dec 12 2021
Amarnath Garg

Table of Contents

How to create Geographical Maps and Graphs in Python

Many open source python libraries now are created to represent the geographical maps. they’re highly customizable and offer a variety of maps depicting areas in several shapes and hues . One such package is Cartopy. you’ll download and install this package in your local environment from Cartopy. you’ll find numerous examples in its gallery.

In the below example we show some of the planet map showing parts of Asia and Australia. you’ll adjust the values of the parameters within the method set_extent to locate different areas of world map.

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig = plt.figure(figsize=(15, 10))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
 # make the map global instead of have it concentrate to
 # the extents of any plotted data
ax.set_extent((60, 150, 55, -25))
ax.stock_img()
ax.coastlines()
ax.tissot(facecolor='purple', alpha=0.8)
plt.show()

Its output is as follows −

7.1 1

Python – Graph Data

CSGraph stands for Compressed Sparse Graph, which focuses on Fast graph algorithms supported sparse matrix representations.

Graph Representations

To begin with, allow us to understand what a sparse graph is and the way it helps in graph representations.

What exactly may be a sparse graph?

A graph is simply a set of nodes, which have links between them. Graphs can represent nearly anything − social network connections, where each node may be a person and is connected to acquaintances; images, where each node may be a pixel and is connected to neighbouring pixels; points during a high-dimensional distribution, where each node is connected to its nearest neighbours and practically anything you’ll imagine.

One very efficient thanks to represent graph data is during a sparse matrix: allow us to call it G. The matrix G is of size N x N, and G[i, j] gives the worth of the connection between node ‘i’ and node ‘j’. A sparse graph contains mostly zeros − that’s , most nodes have only a couple of connections. This property seems to be true in most cases of interest.

The creation of the sparse graph submodule was motivated by several algorithms utilized in scikit-learn that included the subsequent −

  • Isomap − A manifold learning algorithm, which needs finding the shortest paths during a graph.
  • Hierarchical clustering − A clustering algorithm supported a minimum spanning tree.
  • Spectral Decomposition − A projection algorithm supported sparse graph laplacians.

As a concrete example, imagine that we might wish to represent the subsequent undirected graph −

7.2

This graph has three nodes, where node 0 and 1 are connected by a foothold of weight 2, and nodes 0 and a couple of are connected by a foothold of weight 1. we will construct the dense, masked and sparse representations as shown within the following example, keeping in mind that an undirected graph is represented by a symmetric matrix.

G_dense = np.array([ [0, 2, 1],
 [2, 0, 0],
 [1, 0, 0] ])
G_masked = np.ma.masked_values(G_dense, 0)
from scipy.sparse import csr_matrix
G_sparse = csr_matrix(G_dense)
print G_sparse.data
The above program will generate the subsequent output.
7.3
array([2, 1, 2, 1])

This is just like the previous graph, except nodes 0 and a couple of are connected by a foothold of zero weight. during this case, the dense representation above results in ambiguities − how can non-edges be represented, if zero may be a meaningful value. during this case, either a masked or a sparse representation must be wont to eliminate the anomaly .

Let us consider the subsequent example.

from scipy.sparse.csgraph import csgraph_from_dense
G2_data = np.array
([
 [np.inf, 2, 0 ],
 [2, np.inf, np.inf],
 [0, np.inf, np.inf]
])

G2_sparse = csgraph_from_dense(G2_data, null_value=np.inf)
print G2_sparse.data

The above program will generate the subsequent output.

array([ 2., 0., 2., 0.])

So, this brings us to the end of blog. This Tecklearn ‘How to create Geographical Maps and Graphs in Python’ blog helps you with commonly asked questions if you are looking out for a job in Python Programming. If you wish to learn Python and build a career in Data Science domain, then check out our interactive, Python with Data Science Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/python-with-data-science/

Python with Data Science Training

About the Course

Python with Data Science training lets you master the concepts of the widely used and powerful programming language, Python. This Python Course will also help you master important Python programming concepts such as data operations, file operations, object-oriented programming and various Python libraries such as Pandas, NumPy, Matplotlib which are essential for Data Science. You will work on real-world projects in the domain of Python and apply it for various domains of Big Data, Data Science and Machine Learning.

Why Should you take Python with Data Science Training?

  • Python is the preferred language for new technologies such as Data Science and Machine Learning.
  • Average salary of Python Certified Developer is $123,656 per annum – Indeed.com
  • Python is by far the most popular language for data science. Python held 65.6% of the data science market.

What you will Learn in this Course?

Introduction to Python

  • Define Python
  • Understand the need for Programming
  • Know why to choose Python over other languages
  • Setup Python environment
  • Understand Various Python concepts – Variables, Data Types Operators, Conditional Statements and Loops
  • Illustrate String formatting
  • Understand Command Line Parameters and Flow control

Python Environment Setup and Essentials

  • Python installation
  • Windows, Mac & Linux distribution for Anaconda Python
  • Deploying Python IDE
  • Basic Python commands, data types, variables, keywords and more

Python language Basic Constructs

  • Looping in Python
  • Data Structures: List, Tuple, Dictionary, Set
  • First Python program
  • Write a Python Function (with and without parameters)
  • Create a member function and a variable
  • Tuple
  • Dictionary
  • Set and Frozen Set
  • Lambda function

OOP (Object Oriented Programming) in Python

  • Object-Oriented Concepts

Working with Modules, Handling Exceptions and File Handling

  • Standard Libraries
  • Modules Used in Python (OS, Sys, Date and Time etc.)
  • The Import statements
  • Module search path
  • Package installation ways
  • Errors and Exception Handling
  • Handling multiple exceptions

Introduction to NumPy

  • Introduction to arrays and matrices
  • Indexing of array, datatypes, broadcasting of array math
  • Standard deviation, Conditional probability
  • Correlation and covariance
  • NumPy Exercise Solution

Introduction to Pandas

  • Pandas for data analysis and machine learning
  • Pandas for data analysis and machine learning Continued
  • Time series analysis
  • Linear regression
  • Logistic Regression
  • ROC Curve
  • Neural Network Implementation
  • K Means Clustering Method

Data Visualisation

  • Matplotlib library
  • Grids, axes, plots
  • Markers, colours, fonts and styling
  • Types of plots – bar graphs, pie charts, histograms
  • Contour plots

Data Manipulation

  • Perform function manipulations on Data objects
  • Perform Concatenation, Merging and Joining on DataFrames
  • Iterate through DataFrames
  • Explore Datasets and extract insights from it

 Scikit-Learn for Natural Language Processing

  • What is natural language processing, working with NLP on text data
  • Scikit-Learn for Natural Language Processing
  • The Scikit-Learn machine learning algorithms
  • Sentimental Analysis – Twitter

Introduction to Python for Hadoop

  • Deploying Python coding for MapReduce jobs on Hadoop framework.
  • Python for Apache Spark coding
  • Deploying Spark code with Python
  • Machine learning library of Spark MLlib
  • Deploying Spark MLlib for Classification, Clustering and Regression

Got a question for us? Please mention it in the comments section and we will get back to you.

 

0 responses on "How to create Geographical Maps and Graphs in Python"

Leave a Message

Your email address will not be published. Required fields are marked *