我正在尝试模拟此图:
如果我有一个相关矩阵,我该如何创建这样的输出?
如果您有一个n x n
相关矩阵M
和一个包含每个 bin 的标签L
的长度向量n
,则可以使用如下内容:
imagesc(M); % plot the matrix
set(gca, 'XTick', 1:n); % center x-axis ticks on bins
set(gca, 'YTick', 1:n); % center y-axis ticks on bins
set(gca, 'XTickLabel', L); % set x-axis labels
set(gca, 'YTickLabel', L); % set y-axis labels
title('Your Title Here', 'FontSize', 14); % set title
colormap('jet'); % set the colorscheme
colorbar on; % enable colorbar
旋转 x 轴标签并非易事,但 MATLAB Central File Exchange 包含一些解决方案。
Adding to @Thomas C. G.'s answer, I'd use:
imagesc(myMatrix);
colormap(jet);
colorbar;
% then to set the axis titles you'll have to use
% Please note the curly braces for the cell array
labelNames = {'USA','NASDAQ','Dow Jones'};
set(gca,'XTickLabel',labelNames); % gca gets the current axis
set(gca,'YTickLabel'labelNames); % gca gets the current axis
Unfortunately, AFAIK, making the text labels vertical as they are in your figure is a bit harder. Maybe somebody else has knowledge to the contrary.