凡例の長さを変えたい

30 views (last 30 days)
Kento SHIRAKATA
Kento SHIRAKATA on 15 Jun 2016
Edited: michio on 5 Sep 2016
legendで作った凡例の長さを変更できませんか? 一点鎖線や破線が綺麗に見えません.
  2 Comments
Kento SHIRAKATA
Kento SHIRAKATA on 15 Jun 2016
Edited: Kento SHIRAKATA on 15 Jun 2016
見ての通り,一点鎖線と破線,実線の凡例が判別できません. 凡例のフォントサイズはlegend関数で定義しています.これも変えたくありません 凡例の長さのみ変更したいです
Joseph Cheng
Joseph Cheng on 15 Jun 2016
"Can not change the length of the legend made with legend? Dashed line and the dotted line does not look clean. As you can see, the dashed line and the broken line, can not be determined by the solid line of legend. Font size of the legend is defined in the legend function. This is also I want to change only the length of No legend want to change" -google translated

Sign in to comment.

Accepted Answer

michio
michio on 5 Sep 2016
Edited: michio on 5 Sep 2016
R2014b以後のバージョンを仮定しますが、legendオブジェクトのプロパティを編集することで、凡例で表示される線の長さを変更することが可能です。
例えば、下記は凡例の線を長く変更しています。
h1 = plot(1:10);
[hh,icons,plots,txt] = legend({'Line 1'});
icons(2).XData = [0.0 0.6];
下記に詳しく解説を加えます。まず、
h1 = plot(1:10);
[hh,icons,plots,txt] = legend({'Line 1'});
との実行で凡例の線に関するオブジェクトがiconsとして出力されます。参考:http://jp.mathworks.com/help/matlab/ref/legend.html#outputarg_icons
icons =
3x1 graphics 配列:
Text (Line 1)
Line (Line 1)
Line (Line 1)
3つのオブジェクトがありますが、1つ目 icons(1) は Line 1という文字列、2つ目 icons(2) は凡例の線の両端で定義される Lineオブジェクト、3つ目 icons(3) は凡例の線の中心をデータに持つ"点" です。実際にプロパティを見てみるとわかりやすいと思います。
>> icons(2)
ans =
Line (Line 1) のプロパティ:
Color: [0 0.4470 0.7410]
LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [0.0571 0.4857]
YData: [0.5000 0.5000]
ZData: [1x0 double]
すべてのプロパティ を表示
>> icons(3)
ans =
Line (Line 1) のプロパティ:
Color: [0 0.4470 0.7410]
LineStyle: 'none'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: 0.2714
YData: 0.5000
ZData: [1x0 double]
すべてのプロパティ を表示
ここで例えば icons(3) のプロパティの内、Marker = 'o' などとすると、凡例の線の中心に丸のマーカーが登場します。
icons(3).Marker = 'o';
凡例の示すものが線ではなく点で表される場合に活用されます。
ここまでで、凡例の線の長さに関しては icons(2)のプロパティを変更することで実現できそうなことがわかります。具体的には線の位置(特にx座標)を定義する XData を変更します。
現時点で XData: [0.0571 0.4857] の値が入っていることが上の表示で確認できますので、短くする場合には例えば
icons(2).XData = [0.1 0.3];
長くする場合には
icons(2).XData = [0.0 0.6];
などと、始点・終点位置を指定して長さを変更することができます。

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!