Effacer les filtres
Effacer les filtres

How to change the Xticket of a figure?

1 vue (au cours des 30 derniers jours)
Rahim Rahim
Rahim Rahim le 29 Déc 2022
I have the following code:
function TEST(A,C,S, D, F, G, MadmApproachName,FILENAME )
A=5
C=6
S=10
TOPSISBWM=15
D=22
F=8
G=99
x1= [1;2;3;4;5;6];
y2 = [A,C,S, D, F, G]
%subplot(1,2,1);
b2=bar(x1,y2);
ylabel('Security (%)');
Name='Security'
ylim([0 max(y2)+10]);
%title('(a)');
title('', 'Units', 'normalized', 'Position', [0.5, -0.1, 0]);
cm = [ 0, 0.4470, 0.7410 ;...
0.8500, 0.3250, 0.0980 ;...
0.9290, 0.6940, 0.1250 ; ...
0.4940, 0.1840, 0.5560 ;...
0.4660, 0.6740, 0.1880 ;...
0.6350, 0.0780, 0.1840] ;
hold on
for k = 1:numel(x1)
b2(k) = bar(x1(k),y2(k), 'FaceColor',cm(k,:));
end
Bar=b2;
for k1 = 1:6
ctr(k1,:) = bsxfun(@plus, Bar(k1).XData, Bar(k1).XOffset'); % Note: ‘XOffset’ Is An Undocumented Feature, This Selects The ‘bar’ Centres
ydt(k1,:) = Bar(k1).YData; % Individual Bar Heights
end
for k1 = 1:size(ctr,2)
format short
text(ctr(:,k1), ydt(:,k1), sprintfc('%.1f',ydt(:,k1)), 'HorizontalAlignment','center', 'VerticalAlignment','bottom')
end
somenames={'NAMSIS-ONE','XAA-DSE','XCDSZA-BSD','CVD-SWZ','AZEZSC-CSA-ASC','XCF-SEZ-AZE'};
set(gca,'xticklabel',somenames)
% hold off
grid on
set(gcf,'Units','Inches');
pos = get(gcf,'Position');
set(gcf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
%set(gcf,'PaperUnits','inches','PaperPosition',[0 0 10 50])
print(gcf,"AB",'-dpdf','-r0')
end
To display a figure of bars. I want to minimize or resize the figure and save it automaticly as a pdf file while the xlable should be writen horizentally.
I mean that I want to write the xlabels horizentally. from
To:

Réponses (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 29 Déc 2022
Use xtickangle(), eg:
A = 5:5:25;
B = {'A1=5', 'A2=10', 'A3=15', 'A4=20', 'A5=25'};
figure(1)
bar(1:5, A, 'facecolor', 'm');
xticks(1:5)
xticklabels({'A1=5', 'A2=10', 'A3=15', 'A4=20', 'A5=25'})
xtickangle(30)
figure(2)
bar(1:5, A, 'facecolor', 'm');
xticks(1:5)
xticklabels({'A1=5', 'A2=10', 'A3=15', 'A4=20', 'A5=25'})
xtickangle(45)
figure(3)
bar(1:5, A, 'facecolor', 'm');
xticks(1:5)
xticklabels({'A1=5', 'A2=10', 'A3=15', 'A4=20', 'A5=25'})
xtickangle(90)
figure(4)
bar(1:5, A, 'facecolor', 'm');
xticks(1:5)
xticklabels({'A1=5', 'A2=10', 'A3=15', 'A4=20', 'A5=25'})
xtickangle(0)

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by