【问题标题】:Fancy Correlation Plots in MATLABMATLAB 中的花式相关图
【发布时间】:2021-03-31 16:17:22
【问题描述】:

我正在尝试找到一种方法来在 MATLAB 中生成这些漂亮的相关图。这些是在 R 中使用“corrplot”函数生成的,但在 MATLAB 中找不到任何类似的代码。任何帮助将不胜感激。

作为简要说明,此函数将创建相关值的色标,并在相关矩阵/图的每个单元格中创建具有相关颜色的圆圈。圆圈的大小也是相关性大小的指标,圆圈越大表示关系越强(正或负)。更多详情请见here

【问题讨论】:

  • 我猜你最好写一个.R 脚本,并从 MATLAB 调用它

标签: matlab plot correlation


【解决方案1】:

我可以根据here提供的代码编写下面的代码来生成类似的图表

% Produce the input lower triangular matrix data
C = -1 + 2.*rand(12,12);
C = tril(C,-1);
C(logical(eye(size(C)))) = 1;
% Set [min,max] value of C to scale colors
clrLim = [-1,1];
% load('CorrColormap.mat') % Uncomment for custom CorrColormap
% Set the  [min,max] of diameter where 1 consumes entire grid square
diamLim = [0.1, 1];
myLabel = {'ICA','Elev','Pr','Rmax','Rmin','Srad','Wspd','Tmin','Tmax','VPD','ET_o','AW'};
% Compute center of each circle
% This assumes the x and y values were not entered in imagesc()
x = 1 : 1 : size(C,2); % x edges
y = 1 : 1 : size(C,1); % y edges
[xAll, yAll] = meshgrid(x,y);
xAll(C==0)=nan; % eliminate cordinates for zero correlations
% Set color of each rectangle
% Set color scale
cmap = jet(256);
% cmap = CorrColormap; % Uncomment for CorrColormap
Cscaled = (C - clrLim(1))/range(clrLim); % always [0:1]
colIdx = discretize(Cscaled,linspace(0,1,size(cmap,1)));
% Set size of each circle
% Scale the size between [0 1]
Cscaled = (abs(C) - 0)/1;
diamSize = Cscaled * range(diamLim) + diamLim(1);
% Create figure
fh = figure();
ax = axes(fh);
hold(ax,'on')
colormap(ax,'jet');
% colormap(CorrColormap) %Uncomment for CorrColormap
tickvalues = 1:length(C);
x = zeros(size(tickvalues));
text(x, tickvalues, myLabel, 'HorizontalAlignment', 'right');
x(:) = length(C)+1;
text(tickvalues, x, myLabel, 'HorizontalAlignment', 'right','Rotation',90);
% Create circles
theta = linspace(0,2*pi,50); % the smaller, the less memory req'd.
h = arrayfun(@(i)fill(diamSize(i)/2 * cos(theta) + xAll(i), ...
    diamSize(i)/2 * sin(theta) + yAll(i), cmap(colIdx(i),:),'LineStyle','none'),1:numel(xAll));
axis(ax,'equal')
axis(ax,'tight')
set(ax,'YDir','Reverse')
colorbar()
caxis(clrLim);
axis off

此处提供了确切的图表: Fancy Correlation Plots in MATLAB

【讨论】:

    【解决方案2】:

    您可以使用plot-corrmat(或修改它,取决于您在 matlab 中的表达能力),以获得相关矩阵的类似可视化(上图)。或者使用 Correlation circles ,看起来也有些相似(下图)...

    https://github.com/elayden/plot-corrmat

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多