Change linewidth of marker in legend

10 ビュー (過去 30 日間)
Max Power
Max Power 2021 年 5 月 16 日
コメント済み: Adam Danz 2021 年 5 月 16 日
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 件のコメント
Adam Danz
Adam Danz 2021 年 5 月 16 日
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';

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by