![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279179/image.png)
adding MAPE/RSME to subplot
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Christoffer Benneballe
el 24 de Mzo. de 2020
Comentada: Ameer Hamza
el 26 de Mzo. de 2020
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279148/image.png)
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 comentarios
Respuesta aceptada
Ameer Hamza
el 24 de Mzo. de 2020
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279179/image.png)
6 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Formatting and Annotation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!