How do I create 2 x-axis labels?

조회 수: 74 (최근 30일)
Carla Gustafsson
Carla Gustafsson 2020년 5월 21일
답변: Srivardhan Gadila 2020년 5월 28일
I have seen a plot created with 2 x-axis labels, how does one do this? I want one label below a certain x-axis value, and another above that value. Below is an example of the plot.
I wanted to use the imagesc function to generate the plot, but found that the axes were of different lengths - the y-axis only went up to 20. So I used the pcolor function to generate my plot. The code is below, if anyone could tell me how to create the 2 labels on each axis, I would be grateful
load ovariancancer;
C= cov(obs');
figure();
pcolor(C);
colorbar ('eastoutside');
shading interp;
hold on;
havecancer = strcmp(grp, 'Cancer');
cancerpatients = numel(havecancer);
no_cancerp = sum(havecancer);
plot( [no_cancerp, no_cancerp], [0, cancerpatients],'k','linewidth',2);
plot( [0,cancerpatients], [no_cancerp, no_cancerp],'k','linewidth',2);
hold off
  댓글 수: 1
darova
darova 2020년 5월 21일
Use annotation or text

댓글을 달려면 로그인하십시오.

답변 (1개)

Srivardhan Gadila
Srivardhan Gadila 2020년 5월 28일
The following code might help you:
% yAxis label 1
t = text(-20,60,'Cancer','HorizontalAlignment','center','FontWeight','bold');
set(t,'Rotation',90);
% yAxis label 2
t = text(-20,180,'Control','HorizontalAlignment','center','FontWeight','bold');
set(t,'Rotation',90);
% xAxis label 1
t = text(60,-20,'Cancer','HorizontalAlignment','center','FontWeight','bold');
% xAxis label 2
t = text(180,-20,'Control','HorizontalAlignment','center','FontWeight','bold');

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by