How to change the linewidth of the axes without affecting the linewidth of the legend box?
조회 수: 127 (최근 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
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!