Borrar filtros
Borrar filtros

How to reduce the size of legend in a fig file?

38 visualizaciones (últimos 30 días)
Sadiq Akbar
Sadiq Akbar el 20 de Oct. de 2022
Comentada: Sadiq Akbar el 20 de Oct. de 2022
I have a MATLAB figure "abc.fig". The size of the legend is very large and has covered the graphs. I want to reduce its size and change its location. How can I do it? I applied the right click options but in vain.
  2 comentarios
Rik
Rik el 20 de Oct. de 2022
This is your 70th question. By now you should be aware of the advice to attach relevant files and code. Why haven't you done that yet?
Sadiq Akbar
Sadiq Akbar el 20 de Oct. de 2022
Thanks for your kind response dear Rik. The file is attached herewith.And the code is given below:
clear all
clc
x=[10 15 20 25 30 35 40];
y1=[0.48 0.31 0.2 0.16 0.15 0.14 0.14];%Purple
y2=[0.46 0.21 0.13 0.08 0.07 0.06 0.06];% Orange
y3=[0.42 0.19 0.14 0.08 0.07 0.06 0.06];% Yellow
y4=[0.38 0.19 0.14 0.12 0.099 0.08 0.08];% Blue
y5=[0.3052 0.1660 0.0844 0.0629 0.0570 0.0365 0.019];% My graph
y6=[0.24 0.13 0.06 0.04 0.02 0.01 0.009];
Purple=[0.4940, 0.1840, 0.5560];
semilogy(x,y1,'o-','color',Purple,'linewidth',2,'MarkerSize',7)
hold
Current plot held
Red=[0.8500, 0.3250, 0.0980];
semilogy(x,y2,'-','color',Red,'linewidth',2,'MarkerSize',7)
yellow=[0.9290, 0.6940, 0.1250];
semilogy(x,y3,'x-','color',yellow,'linewidth',2,'MarkerSize',9)
blue=[0.3010, 0.7450, 0.9330];
semilogy(x,y4,'v-','color',blue,'linewidth',2,'MarkerSize',7)
semilogy(x,y5,'g','linewidth',2);
semilogy(x,CRLB,'k--','linewidth',2);
Unrecognized function or variable 'CRLB'.
xlabel('Signal to Noise Ratio')
ylabel('Root Mean Sqaure Error (RMSE)')
title('RMSE vs SNR with N=10')
grid on
legend('Separate Learning Methodology based','First Principle based Method','Orthogonal Moving Machine Method','Direct and Indirect Method','FPA','Clever Root based Large byproduct')

Iniciar sesión para comentar.

Respuestas (1)

Fabio Freschi
Fabio Freschi el 20 de Oct. de 2022
You can try playing with the 'location' optional input, for example using
legend('blabla1','blabla2','Location','bestoutside')
Many options are available (check out this link)
  3 comentarios
Fabio Freschi
Fabio Freschi el 20 de Oct. de 2022
Did you play with all options for the location? For example the
clear all, close all
x=[10 15 20 25 30 35 40];
y1=[0.48 0.31 0.2 0.16 0.15 0.14 0.14];%Purple
y2=[0.46 0.21 0.13 0.08 0.07 0.06 0.06];% Orange
y3=[0.42 0.19 0.14 0.08 0.07 0.06 0.06];% Yellow
y4=[0.38 0.19 0.14 0.12 0.099 0.08 0.08];% Blue
y5=[0.3052 0.1660 0.0844 0.0629 0.0570 0.0365 0.019];% My graph
y6=[0.24 0.13 0.06 0.04 0.02 0.01 0.009];
Purple=[0.4940, 0.1840, 0.5560];
figure
semilogy(x,y1,'o-','color',Purple,'linewidth',2,'MarkerSize',7)
hold
Current plot held
Red=[0.8500, 0.3250, 0.0980];
semilogy(x,y2,'-','color',Red,'linewidth',2,'MarkerSize',7)
yellow=[0.9290, 0.6940, 0.1250];
semilogy(x,y3,'x-','color',yellow,'linewidth',2,'MarkerSize',9)
blue=[0.3010, 0.7450, 0.9330];
semilogy(x,y4,'v-','color',blue,'linewidth',2,'MarkerSize',7)
semilogy(x,y5,'g','linewidth',2);
semilogy(x,y6,'k--','linewidth',2);
xlabel('Signal to Noise Ratio')
ylabel('Root Mean Sqaure Error (RMSE)')
title('RMSE vs SNR with N=10')
grid on
lgd = legend('Separate Learning Methodology based','First Principle based Method','Orthogonal Moving Machine Method','Direct and Indirect Method','FPA','Clever Root based Large byproduct');
lgd.Location = 'southoutside';
You have a lot of text in your legend. You shoud try to compress the expalnations.
If you really want to keep the current text, you can try to reduce the fontsize, even I don't recommend this option for legibility.
clear all
clc
x=[10 15 20 25 30 35 40];
y1=[0.48 0.31 0.2 0.16 0.15 0.14 0.14];%Purple
y2=[0.46 0.21 0.13 0.08 0.07 0.06 0.06];% Orange
y3=[0.42 0.19 0.14 0.08 0.07 0.06 0.06];% Yellow
y4=[0.38 0.19 0.14 0.12 0.099 0.08 0.08];% Blue
y5=[0.3052 0.1660 0.0844 0.0629 0.0570 0.0365 0.019];% My graph
y6=[0.24 0.13 0.06 0.04 0.02 0.01 0.009];
Purple=[0.4940, 0.1840, 0.5560];
figure
semilogy(x,y1,'o-','color',Purple,'linewidth',2,'MarkerSize',7)
hold
Current plot held
Red=[0.8500, 0.3250, 0.0980];
semilogy(x,y2,'-','color',Red,'linewidth',2,'MarkerSize',7)
yellow=[0.9290, 0.6940, 0.1250];
semilogy(x,y3,'x-','color',yellow,'linewidth',2,'MarkerSize',9)
blue=[0.3010, 0.7450, 0.9330];
semilogy(x,y4,'v-','color',blue,'linewidth',2,'MarkerSize',7)
semilogy(x,y5,'g','linewidth',2);
semilogy(x,y6,'k--','linewidth',2);
xlabel('Signal to Noise Ratio')
ylabel('Root Mean Sqaure Error (RMSE)')
title('RMSE vs SNR with N=10')
grid on
lgd = legend('Separate Learning Methodology based','First Principle based Method','Orthogonal Moving Machine Method','Direct and Indirect Method','FPA','Clever Root based Large byproduct');
lgd.FontSize = 7;
Sadiq Akbar
Sadiq Akbar el 20 de Oct. de 2022
Thank you very much dear Fabio Freschi for your guiadance. Yes you are right that decreasing the font size seems bad. Your above code is very good. But since I reduce the size of the figure, so with that the legend area becomes large abd covers the graphs. With your code, the legend goes down and its very good but since I reduce the size of theb figure window so it seems very strnage to me.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by