1

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. At the end of my script I would like to export the figure as a .eps file. If I am using the print() function, the linewidth of the marker is always changing back (to the unwanted thicker linewidth) in the legend.

Can anybody help me to fix it that the linewidth of the marker in the plot and legend does have the correct (thiner) linewidth (as the solid line)?

clear all
clc
close all

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')
3
  • 2
    Legends are hard to tweak. But I’m sure it can be done somehow. One unrelated comment: clear all is bad practice. It clears a whole lot more than just the workspace, and causes subsequent code to run slower. Just do clear to clear the workspace. Commented May 14, 2021 at 13:21
  • Does this Q/A on the MathWorks forum help?
    – a11
    Commented May 17, 2021 at 18:01
  • @a11 sorry but it does not :-( If you run the script of mine from above (without the print() function) you can see what i want to do. It would be great that the circle marker in the legend does have the linewidth of 1.0! If i add the print() function the linewidth of the marker in the legend is changing to 3.0 in the output .eps file. Do you know what i mean?
    – WM_noob5
    Commented May 18, 2021 at 7:53

0

Browse other questions tagged or ask your own question.