Legend in columns with different size markers than in plot
7 views (last 30 days)
Show older comments
Evangelos Stefanidis
on 25 Jan 2022
Edited: Evangelos Stefanidis
on 29 Jan 2022
Hello,
I would like to increase the size of the markers OMLY in the legend of a plot. The legend is in 2 columns.
Here what I have:
%Data
x1=1:10;
m1= x1+1.8*rand(1,10);
m2=3+m1;
m3=5+m1;
m4=6+m1;
err1=1.2*rand(1,10);
err2=1.2*rand(1,10);
err3=1.2*rand(1,10);
err4=1.2*rand(1,10);
%Figure
f=figure;
errorbar(x1,m1,err1,'^','Color', 'g','MarkerFaceColor','g','MarkerSize',8,'LineWidth',2)
hold on
errorbar(x1,m2,err2,'s','MarkerFaceColor','r','Color','r','MarkerSize',8,'LineWidth',2)
errorbar(x1,m3,err3,'d','Color', 'k','MarkerFaceColor','k','MarkerSize',8,'LineWidth',2)
errorbar(x1,m4,err4,'o','MarkerFaceColor','b','Color','b','MarkerSize',8,'LineWidth',2)
%plot size, position and format
set(gcf,'position',[550,250,1000,600])
set(gca,'fontname','calibri','box','off','FontSize', 30)
set(gca,'LineWidth',1,'TickLength',[0.025 0.025]);
set(gcf,'color','w');
%Axis labeling and format
xlabel('\textbf{L, }{\boldmath $\mathrm{mm}$}','Interpreter','latex', 'FontSize', 32,'fontweight','bold')
ylabel({'{\boldmath$\mathrm{\overline{Q}, \ mJ}$}'},'Interpreter','latex', 'FontSize', 32,'fontweight','bold')
set(gca,'XMinorTick','on','YMinorTick','on')
legend('Type 1','Type 2','Type 3','Type 4','Location','northwest','FontSize', 32,'NumColumns',2,'Box','off');
% Fake plots for the legend (didn't work)
% h(1)=errorbar(nan,nan,nan,'^','Color', 'g','MarkerFaceColor','g','MarkerSize',20,'LineWidth',2, 'DisplayName', 'Type 1');
% h(2)=errorbar(nan,nan,nan,'s','MarkerFaceColor','r','Color','r','MarkerSize',20,'LineWidth',2, 'DisplayName', 'Type 2');
% h(3)=errorbar(nan,nan,nan,'d','Color', 'k','MarkerFaceColor','k','MarkerSize',20,'LineWidth',2, 'DisplayName', 'Type 3');
% h(4)=errorbar(nan,nan,nan,'o','MarkerFaceColor','b','Color','b','MarkerSize',20,'LineWidth',2, 'DisplayName', 'Type 4');
% legend(h,'Location','northwest','FontSize', 32,'NumColumns',2,'Box','off');
%Plot full window
T = get(gca,'tightinset');
set(gca,'position',[T(1) T(2) 1-T(1)-T(3) 1-T(2)-T(4)]);
hold off
I tried the classic trick:
f=figure;
t1=errorbar(x1,m1,err1,'^','Color', 'g','MarkerFaceColor','g','MarkerSize',8,'LineWidth',2);
hold on
t2=errorbar(x1,m2,err2,'s','MarkerFaceColor','r','Color','r','MarkerSize',8,'LineWidth',2);
t3=errorbar(x1,m3,err3,'d','Color', 'k','MarkerFaceColor','k','MarkerSize',8,'LineWidth',2);
t4=errorbar(x1,m4,err4,'o','MarkerFaceColor','b','Color','b','MarkerSize',8,'LineWidth',2);
%plot size, position and format
set(gcf,'position',[550,250,1000,600])
set(gca,'fontname','calibri','box','off','FontSize', 30)
set(gca,'LineWidth',1,'TickLength',[0.025 0.025]);
set(gcf,'color','w');
%Axis labeling and format
xlabel('\textbf{L, }{\boldmath $\mathrm{mm}$}','Interpreter','latex', 'FontSize', 32,'fontweight','bold')
ylabel({'{\boldmath$\mathrm{\overline{Q}, \ mJ}$}'},'Interpreter','latex', 'FontSize', 32,'fontweight','bold')
set(gca,'XMinorTick','on','YMinorTick','on')
legend('Type 1','Type 2','Type 3','Type 4','Location','northwest','FontSize', 32,'NumColumns',2,'Box','off');
[h,icons,plots,legend_text] =legend([t1 t3 t2 t4],'Location','northwest','FontSize', 30,'NumColumns',2,'Box','off');
icons = findobj(icons, 'type', 'line');
set(icons, 'Markersize', 15);
But the legent is in one column. The one column problem appear every time I have x=legend(). Also the errorbar in the legent dissapear.
Also as you see in my code I tried to create fake plots to use these in the legend, but also didn't work. Any ideas?
Thank you in advance.
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!