% Generate random data rng(5) X = randn(100,80) + [(linspace(-1,2.5,100)').*ones(1,15), (linspace(.5,-.7,100)').*ones(1,15), ... (linspace(.1,-.7,100)').*ones(1,15), (linspace(.9,-.2,100)').*ones(1,15), ... (linspace(-.1,.7,100)').*ones(1,10), (linspace(-.9,-.2,100)').*ones(1,10)]; Y = randn(100,8) + [(linspace(-1,2.5,100)').*ones(1,2), (linspace(.5,-.7,100)').*ones(1,3), (linspace(-1,-2.5,100)').*ones(1,3)]; Data = corr(X,Y); % Define color map and color range CMap = parula(); % CMap = slanCM(136); % Use this if the slanCM function is available CLim = [-1,1]; % Define variable names arbitrarily XName{80} = []; for i = 1:80 XName{i} = ['slan', num2str(i)]; end YName{8} = []; for i = 1:8 YName{i} = ['var', num2str(i)]; end % Angle range theta1 = pi/4; theta2 = -3*pi/2; % Radius range R1 = 1; R2 = 2; % Angle and radius preprocessing ============================================= theta3 = (theta2 - theta1)./size(Data,1); theta4 = theta1 + theta3/2; theta5 = theta2 - theta3/2; R3 = (R2 - R1)./size(Data,2); R4 = R1 + R3/2; R5 = R2 - R3/2; % Start plotting ============================================================= fig = figure('Units', 'normalized', 'Position', [0,0,1,1]); fig.Color = [1,1,1]; ax = axes(fig); hold on ax.XLim = [-2.5,2.5]; ax.YLim = [-2.5,2.5]; ax.DataAspectRatio = [1,1,1]; ax.XColor = 'none'; ax.YColor = 'none'; % Plot circular heatmap x = linspace(CLim(1), CLim(2), size(CMap,1))'; y1 = CMap(:,1); y2 = CMap(:,2); y3 = CMap(:,3); colorFunc = @(X)[interp1(x,y1,X,'pchip'), interp1(x,y2,X,'pchip'), interp1(x,y3,X,'pchip')]; tS = linspace(0,1,50); for i = 1:size(Data,2) for j = 1:size(Data,1) tX = [i-1,i]./size(Data,2); tY = [j-1,j]./size(Data,1); tX = tX + 1; tY = theta1 + (theta2 - theta1).*tY; tR = [tX(1).*ones(1,50), tX(2).*ones(1,50)]; tT = [tY(1) + (tY(2)-tY(1)).*tS, tY(2) + (tY(1)-tY(2)).*tS]; fill(ax, tR.*cos(tT), tR.*sin(tT), colorFunc(Data(j,i)), 'EdgeColor', [1,1,1], 'LineWidth', .7) end end % Add radial labels (X variables) for i = 1:size(Data,1) tT = theta4 + (theta5 - theta4).*(i-1)./(size(Data,1)-1); if tT > -pi/2 text(ax, (R2+0.2).*cos(tT), (R2+0.2).*sin(tT), XName{i}, ... 'FontSize', 10, 'FontName', 'Cambria', 'Rotation', tT./pi.*180); else text(ax, (R2+0.2).*cos(tT), (R2+0.2).*sin(tT), XName{i}, ... 'FontSize', 10, 'FontName', 'Cambria', 'Rotation', tT./pi.*180+180, 'HorizontalAlignment', 'right'); end end % Add circumferential labels (Y variables) for i = 1:size(Data,2) tR = R4 + (R5 - R4).*(i-1)./(size(Data,2)-1); text(ax, tR.*cos(theta1-0.1), tR.*sin(theta1-0.1), YName{i}, ... 'FontSize', 10, 'FontName', 'Cambria', 'HorizontalAlignment', 'right'); end % Add colorbar colormap(CMap) clim(CLim) cb = colorbar(); cb.Position(2) = 0.2; cb.Position(4) = 0.6; cb.Position(1) = 0.85; cb.Position(3) = 0.03; cb.FontName = 'Cambria'; cb.FontSize = 12; % Add title title(ax, 'Circular Heatmap', 'FontSize', 16, 'FontWeight', 'bold', 'FontName', 'Cambria');