adding MAPE/RSME to subplot
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi MathWorks
I have a subplot consisting of four figures. For each figure I would like to add a name (MAPE) and the calculated value (perhaps in the top left corner of within the axes).
I have tried to work with text, legend or annotation, but without success.
At the moment the plots looks as one the attached .png-file. The value does not fit in the top left corner perfectly each time, it's too big in fontsize and does not look nice.
Is there any way to improve it and even add two more variables to the "text box" as I would also like RMSE and R^2?
The script for the plot looks as follows and I have attached a copy of the script and data:
f=figure;
for i = 1:4
subplot(2,2,i);
axis([min(fittedValues(:,i)) max(fittedValues(:,i)) min(meanReturns(:,i)) max(meanReturns(:,i))]);
set(gca,'FontSize',6)
ref = refline(1,0);
ref.Color = plotColors(3,:);
ref.LineWidth = 1.2;
title(titles(1,i),'FontSIze', 7);
xlabel('Model implied returns (in %)', 'FontSize', 6);
ylabel('Avg. monthly realized returns (in %)', 'FontSize', 6);
box on
hold on
labels = {'11','12','13','14','15','21','22','23','24','25',...
'31','32','33','34','35','41','42','43','44','45','51','52','53','54','55'};
text(fittedValues(:,i),meanReturns(:,i), labels,'HorizontalAlignment','center','FontSize',6,'Color',plotColors(1,:));
text(min(fittedValues(:,i)), max(meanReturns(:,i))-0.05, sprintf('MAPE = %.4f', vwMAPE(i,1)))
hold off
end
All the best,
Christoffer
댓글 수: 0
채택된 답변
Ameer Hamza
2020년 3월 24일
Try something like this
f = figure();
% random values
MAPE = [1.234 2.123 1.034 0.234];
MSE = [2.20 1.20 2.23 1.10];
R2 = [0.9 0.7 0.8 0.9];
% make random graphs
ax = gobjects(1,4);
for i=1:4
ax(i) = subplot(2,2,i);
plot((1:10)+2*rand(1,10));
xLeft = ax(i).XLim(1);
xDiff = diff(ax(i).XLim);
yTop = ax(i).YLim(2);
yDiff = diff(ax(i).YLim);
text(xLeft+0.05*xDiff, yTop-0.05*yDiff, ['MAPE=' num2str(MAPE(i))], ...
'HorizontalAlignment', 'left', 'VerticalAlignment', 'top', 'Interpreter', 'latex');
text(xLeft+0.05*xDiff, yTop-0.15*yDiff, ['MSE=' num2str(MSE(i))], ...
'HorizontalAlignment', 'left', 'VerticalAlignment', 'top', 'Interpreter', 'latex');
text(xLeft+0.05*xDiff, yTop-0.25*yDiff, ['$R^2$=' num2str(R2(i))], ...
'HorizontalAlignment', 'left', 'VerticalAlignment', 'top', 'Interpreter', 'latex');
end
Result:
댓글 수: 6
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!