How to change the linewidth of the axes without affecting the linewidth of the legend box?
133 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jing Ci Neo
el 20 de Sept. de 2019
Comentada: Jing Ci Neo
el 23 de Sept. de 2019
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
0 comentarios
Respuesta aceptada
dpb
el 21 de Sept. de 2019
Editada: dpb
el 21 de Sept. de 2019
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!