How to change color bar? how to keep initial abscisses values?
Afficher commentaires plus anciens
This is my code before adding a command to display values at the tip of the bars.
X = categorical({'1024','512','256','128'});
X = reordercats(X,{'1024','512','256','128'});
x=[1024,512,256,128];
Pitch= 17*10^(-3)
tai15 = []
for i = 1:length(x)
T = (x(i)*Pitch)/15
tai15=[tai15, T]
end
tai20=[]
for i = 1:length(x)
T = (x(i)*Pitch)/20
tai20=[tai20, T]
end
tai30=[]
for i = 1:length(x)
T = (x(i)*Pitch)/30
tai30=[tai30, T]
end
Tail=[tai15; tai20; tai30]
y=Tail'
b = bar(X, y)
b(1).FaceColor = [1 0 0]
b(2).FaceColor = [0 1 0]
b(3).FaceColor = [0 0 1]
legend({'X15','X20','X30'})
set(gcf,'color','w') % pour les bordures.
set(gca, 'FontSize', 9, 'linewidth', 1, 'FontName','Times New Roman'); %la taille des éléments sur les axes.
xlabel('Spatial resolution (pixels)','FontSize',12, 'FontName','Times New Roman')
ylabel('scene size (mm²)','FontSize',12, 'FontName','Times New Roman')
When i add the command to display values at the tip of the bars, bar color changes? and abscisses changes also? I want to keep the initial color and abscisses?
X = categorical({'1024','512','256','128'});
X = reordercats(X,{'1024','512','256','128'});
x=[1024,512,256,128];
Pitch= 17*10^(-3)
tai15 = []
for i = 1:length(x)
T = (x(i)*Pitch)/15
tai15=[tai15, T]
end
tai20=[]
for i = 1:length(x)
T = (x(i)*Pitch)/20
tai20=[tai20, T]
end
tai30=[]
for i = 1:length(x)
T = (x(i)*Pitch)/30
tai30=[tai30, T]
end
Tail=[tai15; tai20; tai30]
y=Tail'
b = bar(X, y)
b(1).FaceColor = [1 0 0]
b(2).FaceColor = [0 1 0]
b(3).FaceColor = [0 0 1]
hBar = bar(y,1);
for k1 = 1:size(y,2)
ctr(k1,:) = bsxfun(@plus, hBar(1).XData, hBar(k1).XOffset'); % Note: ‘XOffset’ Is An Undocumented Feature, This Selects The ‘bar’ Centres
ydt(k1,:) = hBar(k1).YData; % Individual Bar Heights
text(ctr(k1,:), ydt(k1,:), sprintfc('%.2f', ydt(k1,:)), 'HorizontalAlignment','center', 'VerticalAlignment','bottom', 'FontSize',8, 'Color','b')
end
legend({'X15','X20','X30'})
set(gcf,'color','w') % pour les bordures.
set(gca, 'FontSize', 9, 'linewidth', 1, 'FontName','Times New Roman'); %la taille des éléments sur les axes.
xlabel('Spatial resolution (pixels)','FontSize',12, 'FontName','Times New Roman')
ylabel('scene size (mm²)','FontSize',12, 'FontName','Times New Roman')
Do you have solution for this problem? i want to keep the initial bar color and abscisses?
Réponse acceptée
Plus de réponses (1)
Jess Lovering
le 3 Oct 2019
Modifié(e) : Jess Lovering
le 3 Oct 2019
You can add this line at the end and see if that works:
xticklabels(x);
Catégories
En savoir plus sur App Building dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!