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

25 次查看(过去 30 天)
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