close

How to plot a 2d matrix in python with colorbar? (like imagesc in Matlab)

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to plot a 2d matrix in python with colorbar? (like imagesc in Matlab) in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to plot a 2d matrix in python with colorbar? (like imagesc in Matlab)?

  1. How to plot a 2d matrix in python with colorbar? (like imagesc in Matlab)?

    import numpy as np import matplotlib.pyplot as plt plt.imshow(np.random.random((50,50))) plt.colorbar() plt.show()

  2. plot a 2d matrix in python with colorbar? (like imagesc in Matlab)

    import numpy as np import matplotlib.pyplot as plt plt.imshow(np.random.random((50,50))) plt.colorbar() plt.show()

Method 1

import numpy as np
import matplotlib.pyplot as plt

plt.imshow(np.random.random((50,50)))
plt.colorbar()
plt.show()

Method 2

Another possibility is to use plt.matshow()

import numpy as np
import matplotlib.pyplot as plt

plt.matshow(np.random.random((50,50)));
plt.colorbar()
plt.show()

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read