首页 文章

在Matlab中创建相关图

提问于
浏览
9

我想模仿这张图:
enter image description here

如果我有一个相关矩阵,我该如何创建这样的输出?

3 回答

  • 1

    如果您有 n x n 相关矩阵 M ,并且长度为 n 的向量 L 包含每个bin的标签,则可以使用如下内容:

    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中央文件交换包含some solutions .

  • 6

    添加到@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
    

    不幸的是,AFAIK,使文本标签垂直,如图所示is a bit harder . 也许其他人有相反的知识 .

  • 2

    要将矩阵绘制为图像,您只需调用两个函数:

    image(myMatrix)
    colormap(jet)
    

    colormap函数定义用于渲染图像的颜色模式 . 您发布的图像使用的是"jet"色彩映射 .

    要显示图像旁边的色标,请使用colorbar功能 .

相关问题