필터 지우기
필터 지우기

How I can add a title in my correlation plot?

조회 수: 3 (최근 30일)
Mahboubeh Molavi-Arabshahi
Mahboubeh Molavi-Arabshahi 2022년 3월 14일
답변: Voss 2022년 3월 14일
This is my code, I want to add a title but on the figure the title is not typed, is there anyone can help me?
y = triu(repmat(n+1, n, n) - (1:n)') + 0.5;
x = triu(repmat(1:n, n, 1)) + 0.5;
x(x == 0.5) = NaN;
scatter(x(:), y(:), 400.*abs(C(:)), C(:), 'filled', 'MarkerFaceAlpha', 0.6)
% enclose markers in a grid
xl = [1:n+1;repmat(n+1, 1, n+1)];
xl = [xl(:, 1), xl(:, 1:end-1)];
yl = repmat(n+1:-1:1, 2, 1);
line(xl, yl, 'color', 'k') % horizontal lines
line(yl, xl, 'color', 'k') % vertical lines
% show labels
text(1:n, (n:-1:1) + 0.5, myLabel1, 'HorizontalAlignment', 'right')
text((1:n) + 0.5, repmat(n + 1, n, 1), myLabel1, 'HorizontalAlignment', 'right', 'Rotation', 270)
h = gca;
colorbar(h);
h.Visible = 'off';
h.Position(4) = h.Position(4)*0.9;
axis(h, 'equal')
colormap('jet')
% caxis([-1,1]);
title('Your Title', 'FontSize', 10); % set title

답변 (1개)

Voss
Voss 2022년 3월 14일
It looks like explicitly stating 'Visible','on' in the call to title() may make the title show up. I'm not sure why this is, since the title 'Visible' property was already 'on' the way you had it. (Of course, the title is still obscured by some of the text objects.)
n = 10;
C = randn(n);
myLabel1 = 'label';
y = triu(repmat(n+1, n, n) - (1:n)') + 0.5;
x = triu(repmat(1:n, n, 1)) + 0.5;
x(x == 0.5) = NaN;
scatter(x(:), y(:), 400.*abs(C(:)), C(:), 'filled', 'MarkerFaceAlpha', 0.6)
% enclose markers in a grid
xl = [1:n+1;repmat(n+1, 1, n+1)];
xl = [xl(:, 1), xl(:, 1:end-1)];
yl = repmat(n+1:-1:1, 2, 1);
line(xl, yl, 'color', 'k') % horizontal lines
line(yl, xl, 'color', 'k') % vertical lines
% show labels
text(1:n, (n:-1:1) + 0.5, myLabel1, 'HorizontalAlignment', 'right')
text((1:n) + 0.5, repmat(n + 1, n, 1), myLabel1, 'HorizontalAlignment', 'right', 'Rotation', 270)
h = gca;
colorbar(h);
h.Visible = 'off';
h.Position(4) = h.Position(4)*0.9;
axis(h, 'equal')
colormap('jet')
% caxis([-1,1]);
title('Your Title', 'FontSize', 10, 'Visible', 'on'); % set title

카테고리

Help CenterFile Exchange에서 Title에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by