How to change the linewidth of the axes without affecting the linewidth of the legend box?

125 次查看(过去 30 天)
I have tried using
ax=gca;ax.LineWidth=2;
which makes both the axis lines and the legend box line thicker. Then I tried to set the legend box lines thinner with
hl = findobj(hobj,'type','line'); set(hl,'LineWidth',1.5);
but it makes both the axis lines and the legend box lines thinner

采纳的回答

dpb
dpb 2019-9-21
编辑:dpb 2019-9-21
Use the two object handles to set their respective properties--although legend does inherit axes properties such as the linewidth from its parent axis which makes a certain amount of sense.
hAx=gca; % create an axes
hL=plot(randn(5,1)); % and a line underneath
hAx.LineWidth=2; % set the axis linewidth for box/ticks
hLg=legend('A'); % put a legend on the figure
hLg.LineWidth=1; % make the legend axes box linewidth smaller
Presuming hobj is the handle of the figure or returned by whichever function used to plot in the axes, hl above is the line in the graph equivalent to hL above. Setting 'LineWidth' for that object changes the linestyle of the line itself, not the same property at all as the axes. And, changing it will change the line characteristics in both as the legend reflects the characteristics of the associated line in the axes to which it belongs. That is a builtin connection that is immutable without trickery to create secondary lines such that the connection between which legend entry is shown and the given line is disguised by creating hidden objects or similar.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by