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

22 Ansichten (letzte 30 Tage)
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])

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 29 Dez. 2018
Bearbeitet: Cris LaPierre am 1 Sep. 2020
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 Kommentare
Netanel shachak
Netanel shachak am 2 Feb. 2023
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 am 2 Feb. 2023
Bearbeitet: Cris LaPierre am 2 Feb. 2023
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by