Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In Matlab I can visualize a matrix data quite easily with

data = rand(10,10); % Createas a 10 x 10 random matrix imagesc(data); colorbar; 

Now I want to do the same thing in python. I already know how to plot a 2d matrix (numpy array):

from matplotlib.pyplot import imshow import numpy as np data = np.random.random((10,10)) imshow(np.asarray(img)) 

but I don't know how to add a colorbar to it. Any ideas?

like image 493
mcExchange Avatar asked Feb 08 '17 15:02

mcExchange


People also ask

Is used for 2D plots of arrays in python?

For plotting graphs in Python, we will use the Matplotlib library. Matplotlib is used along with NumPy data to plot any type of graph. From matplotlib we use the specific function i.e. pyplot(), which is used to plot two-dimensional data.


1 Answers

import numpy as np import matplotlib.pyplot as plt  plt.imshow(np.random.random((50,50))) plt.colorbar() plt.show() 
like image 134
Alexandre Kempf Avatar answered Sep 22 '22 15:09

Alexandre Kempf