legend内のplotの長さを長くして,さらに文章がboxからはみ出ないようにする.
조회 수: 17 (최근 30일)
이전 댓글 표시
太い線でplotしてlegendを表示すると,legend内に表示される線が短く,破線などが見分けにくい問題があります.
それを解決するため以下のようにコードを変更しましたが,
x = 1:0.1:10;
y = sin(x);
plot(x, y, '--', 'Linewidth',10);
[hh,icons,plots,txt] = legend('the graph of sin(x)','Location','eastoutside');
icons(1).Position(1) = 0.72;
icons(2).XData = [0 0.7];
今度はlegendのtextが右にはみ出てしまいます.
解決すべく,hh.Positionを変更したりもしたのですが,するとhh.Locationがnoneになってしまい,今度はlegendが図に重なってしまいます.
legend内のplotの長さを長くして,さらに文章がboxからはみ出ないようにするにはどうすればよいのでしょうか?
댓글 수: 2
Atsushi Ueno
2023년 12월 21일
質問に答えていませんが、目的から考えて点線の間隔が短くなれば事足りるのではないでしょうか?
p = plot(1:0.1:10, sin(1:0.1:10), ':', 'Linewidth',10);
채택된 답변
Atsushi Ueno
2023년 12월 21일
편집: Atsushi Ueno
2023년 12월 24일
- gca 関数でグラフの軸オブジェクトを取得し、グラフの幅を変更します
- legend 関数の出力である Legend オブジェクト を取得し、legend の幅を変更します
- figure 関数の出力である Figure オブジェクト を取得し、figure の幅を変更します
f = figure;
x = 1:0.1:10;
y = sin(x);
plot(x, y, '--', 'Linewidth',10);
[hh,icons,plots,txt] = legend('the graph of sin(x)','Location','eastoutside');
icons(1).Position(1) = 0.72;
icons(2).XData = [0 0.7];
f.Position(3) = 1500; % figureの幅
ax = gca;
ax.Position(3) = 0.3; % グラフ軸の幅
hh.Position(3) = 0.4; % legendの幅
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!