How to Add text to 3-D bar chart (bar3) on the top of each bar?

조회 수: 44 (최근 30일)
Nibras Abo Alzahab
Nibras Abo Alzahab 2018년 12월 28일
편집: Cris LaPierre 2023년 2월 2일
I am trying to visualise data as a 3-D bar chart. I used "bar3" function.
How I can add text (the value) on the top of each chart?
I tried to write the following code, and it works well.
S.jpg
But I still need to add some text on the plot.
DATA_Sensitivity=[
72.71683742 46.68656078 52.79741961 52.20167451 50.83051373;
74.50372032 52.25829563 64.02911011 62.78763198 61.79562594;
63.10542986 50.6254902 56.6627451 53.09019608 52.96666667;
67.62513583 58.98431373 62.33590527 62.04112554 65.53002292;
79.37428385 53.68823529 62.44705882 67.95098039 64.88431373];
%% Sensitivity Bar Chart
figure
h = bar3(DATA_Sensitivity,'detached');
hh = get(h(3),'parent');
set(hh,'yticklabel',['PSD';'STD';'AM ';'SE ';'DE ']);
hhh = get(h(3),'parent');
set(hhh,'xticklabel',['ANN';'DT ';'LDA';'SVM';'KNN']);
ax = gca;
ax.YLabel.String = 'features';
ax.YLabel.FontSize = 16;
ax.XLabel.String = 'classfiers';
ax.XLabel.FontSize = 16;
ax.ZLabel.String = 'Sensitivity';
ax.ZLabel.FontSize = 16;
ax.Title.String = 'Avrage Sensitivity';
ax.Title.FontSize = 16;
zlim([0 100])

채택된 답변

Cris LaPierre
Cris LaPierre 2018년 12월 29일
편집: Cris LaPierre 2020년 9월 1일
What will the labels be?
Have you looked at this answer yet?
Assuming your labels are numeric, here's how I'd do it using the code you've provided
[X,Y] = meshgrid(1:size(DATA_Sensitivity,2), 1:size(DATA_Sensitivity,1));
text(X(:), Y(:), DATA_Sensitivity(:), num2str(DATA_Sensitivity(:)), 'HorizontalAlignment','center', 'VerticalAlignment','bottom')
  댓글 수: 19
Netanel shachak
Netanel shachak 2023년 2월 2일
Hi,
Thanks for the great answer above!
Is there any way to get more space between the different bars (Y,M,C,K)?
Thanks
Cris LaPierre
Cris LaPierre 2023년 2월 2일
편집: Cris LaPierre 2023년 2월 2일
There does not appear to be a property in bar3 that allows for adjusting the spacing in the y direction.
You can specify your inputs for y using the following syntax, but if the increment is uniform between the values, it always gets normalized back to looking exactly the same.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by