Python | Drawing Symmetric Matrix Colormap Plot using Matplotlib

In this tutorial, we are going to learn how to draw a symmetric matrix in python using matplotlib?
Submitted by Anuj Singh, on August 07, 2020

Matplotlib provides an inbuilt function for plotting matrices i.e. matplotlib.pyplot.matshow(). We first define a diagonal matrix using NumPy library function numpy.diag() and then plot it using matplotlib. There are a number of color maps available and for illustration, we are using inferno and cool color maps in this article.

Drawing Symmetric Matrix Colormap Plot  (1)

Drawing Symmetric Matrix Colormap Plot  (2)

Drawing Symmetric Matrix Colormap Plot  (3)

Python code for drawing symmetric matrix colormap plot using matplotlib

import numpy as np
import matplotlib.pyplot as plt

# Example 1
mata = np.random.random([5,4])
mataa = np.matmul(mata, mata.T)
plt.imshow(mataa)
plt.axis(False)
plt.show()

# Example 2
mata = np.random.random([5,4])
mataa = np.matmul(mata, mata.T)
plt.imshow(mataa, cmap='PuBuGn_r')
plt.axis(False)
plt.show()

# Example 3
x = np.arange(5)
y = np.random.randint(1,5,5)
mata = np.random.random([5,4])
mataa = np.matmul(mata, mata.T)
plt.imshow(mataa, cmap='GnBu')
plt.plot(x,y)
plt.axis(False)
plt.show()

Output:

Output is as Figure





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.