I have a large matrix of size 500 X 18904.
Since most of the values are zeros, I'm not able to visualise the pattern clearly as the zeroes dominate in the colorbar.
To look at the data more closely, I need to zoom in for different segments of image. Is there any reliable way to visualise this data using colorbar?.
Here is my code and output.
import numpy as np
import matplotlib.pyplot as plt
import scipy.io as sio
j = sio.loadmat('UV_matrix.mat')
k = j['UV']
plt.imshow(k, aspect='auto')
plt.show()
The output
I can think of two options by using numpy arrays.
Assuming your data is mostly higher than zero but there are a lot of zeros.:
vmin = some_value_higher_than_zero
plt.matshow(k,aspect='auto',vmin=vmin)
Setting all zeros to NaNs. they are automatically left out.
k[k==0.0]=np.nan
plt.matshow(k,aspect='auto')
NB. imshow and matshow work both here.
Another option, when your matrix is really sparse is to use scatterplots.
x,y = k.nonzero()
plt.scatter(x,y,s=100,c=k[x,y]) #color as the values in k matrix
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With