legend内のplotの長さを長くして,さらに文章がboxからはみ出ないようにする.
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kato Yusuke
le 21 Déc 2023
Commenté : Kato Yusuke
le 25 Déc 2023
太い線で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 commentaires
Atsushi Ueno
le 21 Déc 2023
質問に答えていませんが、目的から考えて点線の間隔が短くなれば事足りるのではないでしょうか?
p = plot(1:0.1:10, sin(1:0.1:10), ':', 'Linewidth',10);
Réponse acceptée
Atsushi Ueno
le 21 Déc 2023
Modifié(e) : Atsushi Ueno
le 24 Déc 2023
- 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の幅
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!