# How to plot with bar3 plot in MATLAB?

9 visualizzazioni (ultimi 30 giorni)
Haitham AL Satai il 20 Ott 2022
Commentato: Haitham AL Satai il 20 Ott 2022
I am trying to draw something like the picture below in Matlab:
with adding the percentage above every bar. Is it possible to get some help, please?
Below is my trying:
B = [86, 82, 80];
B2 = [91, 88, 85];
B3 = [98, 95, 89];
z = [B; B2; B3];
environment = [30*30, 50*50, 100*100];
bar3(z)
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Fabio Freschi il 20 Ott 2022
Check the code below, Hope it helps
clear variables, close all
B = [86, 82, 80];
B2 = [91, 88, 85];
B3 = [98, 95, 89];
z = [B; B2; B3];
environment = [30*30, 50*50, 100*100];
% change the width
bar3(z,0.3)
% label x axis
xticklabels({'Bezier 1','Bezier 2','Bezier 3'})
% label y axis
yticklabels({'30*30', '50*50', '100*100'})
ylabel('Grid size')
% label z axis
zlabel('Success rate')
% set view
view([1 1 1])
% text above bar
xt = repmat(1:3,1,3);
yt = repmat(1:3,3,1);
zt = repmat(105,9,1);
text(xt(:),yt(:),zt(:),[num2str(z(:)),repmat('%',9,1)])
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Haitham AL Satai il 20 Ott 2022
@Fabio Freschi Thank you very much dear sir.

Accedi per commentare.

### Più risposte (1)

Kevin Holly il 20 Ott 2022
Modificato: Kevin Holly il 20 Ott 2022
B = [86, 82, 80];
B2 = [91, 88, 85];
B3 = [98, 95, 89];
z = [B; B2; B3]';
environment = ["30*30", "50*50", "100*100"];
b = bar3(z,0.3);
b(1).FaceColor = 'r';
b(2).FaceColor = 'b';
b(3).FaceColor = [.2 .5 .2];
grid on
h=gca;
h.XTickLabel = ["Beizer 1";"Beizer 2";"Beizer 3"];
h.YTickLabel = environment;
ylabel('Grid Size')
zlabel('Success Rate')
view(-15,16)
Edit:
% Borrowed from Fabio
xt = repmat(1:3,1,3);
yt = repmat(1:3,3,1);
zt = repmat(105,9,1);
text(yt(:),xt(:),zt(:),[num2str(z(:)),repmat('%',9,1)])
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Haitham AL Satai il 20 Ott 2022
@Kevin Holly Thank you very much dear sir.

Accedi per commentare.

### Categorie

Scopri di più su Discrete Data Plots in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by