How to set legend for a line segment?

8 ビュー (過去 30 日間)
Mr M.
Mr M. 2015 年 11 月 5 日
編集済み: Thorsten 2015 年 11 月 10 日
How to add legend to this?: line([x1 x2],[y1,y2],'color','r','linestyle','--');

回答 (1 件)

Thorsten
Thorsten 2015 年 11 月 5 日
x1 = 10; x2 = 20; y1 = 12; y2 = 34;
line([x1 x2],[y1,y2],'color','r','linestyle','--');
legend('my dashed red line')
  2 件のコメント
Mr M.
Mr M. 2015 年 11 月 9 日
編集済み: Mr M. 2015 年 11 月 9 日
Yes, but I want to use it in general. For example I have plot; plot; line; plot; hist; line; plot; bars; etc. And how to add legend to the lines?
Thorsten
Thorsten 2015 年 11 月 10 日
編集済み: Thorsten 2015 年 11 月 10 日
h = line([x1 x2],[y1,y2],'color','r','linestyle','--');
legend(h, 'my dashed red line')
If this does not the job, please post a minimal working example of what you try to do and what goes wrong.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by