Clear Filters
Clear Filters

Write xtick in two lines and write values of plot in figure

27 views (last 30 days)
I am unable to remove the overlaping in xticks. For longer xticks, how to write it in two lines. In addition how to write the values of plot in the figure from the data. I searched throughout to failed to find a convincing answer
MAPE =[0.612 0.530 0.667 0.581 0.530 0.483
0.560 0.348 0.586 0.505 0.365 0.309
0.501 0.320 0.564 0.507 0.311 0.225
0.505 0.244 0.515 0.519 0.452 0.250
0.508 0.285 0.547 0.415 0.388 0.250
0.495 0.342 0.554 0.506 0.374 0.268
0.477 0.170 0.494 0.510 0.317 0.283
0.495 0.210 0.471 0.417 0.254 0.134
0.462 0.195 0.426 0.492 0.216 0.257
0.506 0.165 0.533 0.481 0.492 0.220]
plot(MAPE(1,:),'linewidth',2);
hold on;
plot(MAPE(5,:),'linewidth',2);
hold on;
plot(MAPE(6,:),'linewidth',2);
hold on;
plot(MAPE(8,:),'linewidth',2);
hold on;
title('MAPE of different models for various parts ');
legend('Face','Back','Ventral','Palm');
xticks([1 2 3 4 5 6]);
xticklabels({'Montague Model','CPE Model','Tregear Level 1','Tregear Level 2','Tregear Level 3','Proposed Model'});
xlabel('Models');
ylabel('MAPE');
legend('boxoff');

Accepted Answer

Mehmed Saad
Mehmed Saad on 9 Apr 2020
Edited: Mehmed Saad on 9 Apr 2020
1. xtick issue
I tried to move xtick to next line but cant, so instead of xtick i used text for that purpose
MAPE =[0.612 0.530 0.667 0.581 0.530 0.483
0.560 0.348 0.586 0.505 0.365 0.309
0.501 0.320 0.564 0.507 0.311 0.225
0.505 0.244 0.515 0.519 0.452 0.250
0.508 0.285 0.547 0.415 0.388 0.250
0.495 0.342 0.554 0.506 0.374 0.268
0.477 0.170 0.494 0.510 0.317 0.283
0.495 0.210 0.471 0.417 0.254 0.134
0.462 0.195 0.426 0.492 0.216 0.257
0.506 0.165 0.533 0.481 0.492 0.220]
% a = figure,
plot(MAPE(1,:),'linewidth',2);
hold on;
plot(MAPE(5,:),'linewidth',2);
hold on;
plot(MAPE(6,:),'linewidth',2);
hold on;
plot(MAPE(8,:),'linewidth',2);
hold on;
% a.Children.TickLabelInterpreter = 'tex';
xticks([1 2 3 4 5 6]);
title('MAPE of different models for various parts ');
legend('Face','Back','Ventral','Palm');
xticklabels({'.','.','.','.','.','.'})
txt= {{'Montague';'Model'},{'CPE';'Model'},{'Tregear';'Level 1'},{'Tregear';'Level 2'},{'Tregear';'Level 3'},{'Proposed';'Model'}};
x=text(1:6,(min(ylim)-0.03)*ones(1,6),txt,'HorizontalAlignment','center');
xlabel('Models');
ylabel('MAPE');
legend('boxoff');
2. Writing Values
Use text to write values on position x,y and to convert data to string, use num2str and to seperate data use strip
MAPE =[0.612 0.530 0.667 0.581 0.530 0.483
0.560 0.348 0.586 0.505 0.365 0.309
0.501 0.320 0.564 0.507 0.311 0.225
0.505 0.244 0.515 0.519 0.452 0.250
0.508 0.285 0.547 0.415 0.388 0.250
0.495 0.342 0.554 0.506 0.374 0.268
0.477 0.170 0.494 0.510 0.317 0.283
0.495 0.210 0.471 0.417 0.254 0.134
0.462 0.195 0.426 0.492 0.216 0.257
0.506 0.165 0.533 0.481 0.492 0.220]
% a = figure,
plot(MAPE(1,:),'linewidth',2);
text(1:6,MAPE(1,:),split(num2str(MAPE(1,:)))) % This is changed
hold on;
plot(MAPE(5,:),'linewidth',2);
text(1:6,MAPE(5,:),split(num2str(MAPE(1,:)))) % This is changed
hold on;
plot(MAPE(6,:),'linewidth',2);
text(1:6,MAPE(6,:),split(num2str(MAPE(1,:)))) % This is changed
hold on;
plot(MAPE(8,:),'linewidth',2);
text(1:6,MAPE(8,:),split(num2str(MAPE(1,:)))) % This is changed
hold on;
% a.Children.TickLabelInterpreter = 'tex';
xticks([1 2 3 4 5 6]);
title('MAPE of different models for various parts ');
legend('Face','Back','Ventral','Palm');
xticklabels({'.','.','.','.','.','.'})
txt= {{'Montague';'Model'},{'CPE';'Model'},{'Tregear';'Level 1'},{'Tregear';'Level 2'},{'Tregear';'Level 3'},{'Proposed';'Model'}};
x=text(1:6,(min(ylim)-0.03)*ones(1,6),txt,'HorizontalAlignment','center');
xlabel('Models');
ylabel('MAPE');
legend('boxoff');

More Answers (0)

Community Treasure Hunt

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

Start Hunting!