在Matlab中创建相关性图

10

我试图模拟这个图表:enter image description here

如果我有一个相关矩阵,如何创建类似的输出?


1
看起来像是 imagesc 命令的输出结果。 - bdecaf
3个回答

8
如果你有一个大小为n x n的相关矩阵M和一个长度为n的标签向量L,你可以使用以下类似的方法:
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中心文件交换包含一些解决方案


对于x轴标签旋转,您可以通过Matlab图形窗口轻松完成:1.从工具栏中选择“显示绘图工具和停靠图形”按钮,https://i.stack.imgur.com/lmiz1.png 2.单击图上的x轴标签https://i.stack.imgur.com/63oKg.png 3.从出现的窗口中选择“更多属性...”https://i.stack.imgur.com/o8NRm.png 4.导航到“XTickLabelRotation”并将其设置为90.0 https://i.stack.imgur.com/FHjz7.png - forough

3

补充@Thomas C. G.的答案,我会使用:

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

很遗憾,据我所知,将文本标签垂直排列如图 是有一定难度的。也许其他人有不同的知识。


1
要将矩阵绘制成图像,您只需要调用两个函数:
image(myMatrix)
colormap(jet)

colormap函数定义了用于渲染图像的颜色模式。您发布的图像正在使用“jet”颜色地图。

要在图像旁边显示颜色刻度,请使用colorbar函数。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接