Change linewidth of marker in legend
10 views (last 30 days)
Show older comments
Hi there,
I would like to change the linewidth of the marker independent from the linewidth of the plotted solid line. By now (see code) I am able to change it in the plot itself. The legend however is a problem. When I export the figure as a .eps file at the end of the script, using the print() function, the linewidth of the marker is always changing back (to the unwanted thicker linewidth) in the legend.
Can anybody please help me to fix my problem?
close all
clear
clc
figure(1)
p1 = plot([1,2,3,4,5,6],[5,4,6,2,4,9],'Marker','o','MarkerSize',12,'MarkerEdgeColor','r', 'LineWidth',3);
hold on
p2 = plot([1,2,3,4,5,6],[9,1,3,4,7,7], 'Marker','+','Markersize',12,'markeredgecolor','r', 'LineWidth',4);
lgd = legend([p1 p2],{'data1','data2'});
drawnow
p1.MarkerHandle.LineWidth = 1.0;
lineEntry = findobj(lgd.EntryContainer, 'Object',p1);
entryMarker = findobj(lineEntry.Icon.Transform, 'Description','Icon Marker');
entryMarker.LineWidth = 1.0;
print(figure(1),'output_fig1','-depsc','-r300')
1 Comment
Adam Danz
on 16 May 2021
Not only does the legend change when printing your figure but the legend reverts back to default behavior any time the content of the axes changes. For example, add another line obj on the axes and you'll see that the legend reverts to default: plot(4,5,'kx').
Setting autoupdate to off solves that but does not solve the reversion during printing lgd.AutoUpdate = 'off';
Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!