python - Plot only one or few rows of a correlation matrix -
i have correlation matrix named corrdata
calculated using numpy.corrcoef
. extract 1 or few rows of matrix, , want plot them instead of whole matrix. because matrix no longer square, not possible plot data using pcolor
, imshow
, or likes.
so want ask best alternative way plot these extracted correlation coefficients , same appearance correlation matrix in terms of coloured squares representing value of correlation coefficient, showing few rows of full matrix.
you can insert singleton dimension in order turn (n,)
1d vector (1, n)
2d array, use pcolor
, imshow
etc. normal:
import numpy np matplotlib import pyplot plt # dummy correlation coefficients coeffs = np.random.randn(10, 10) row = coeffs[0] # indexing none (or equivalently, np.newaxis) inserts singleton # dimension plt.imshow(row[none, :], cmap=plt.cm.jet, interpolation='nearest')
see here more ways convert 1d vector 2d array.
Comments
Post a Comment