フィルターのクリア

adding appropriate legend data

3 ビュー (過去 30 日間)
Art
Art 2013 年 8 月 8 日
Using Matlab 2009a I created a plot that contains data from multiple sources. The sources can be input as either individual directories or as multiple sets of directories.
In the case of plotting from individual directories, the legend is simply the names of the individual directories.
In the case where multiple sets of directories are plotted (each directory in a set with the same color), I would like to see a legend like "set-1 blue, set-2 red, etc". This appears to be a problem, as legend will align each character set given with the color of the next line drawn, not the set as a whole. The result is of course that the legend contains the same colors for all sets (at least while the number of entries in the legend is smaller than the number of entries in the first set).
Is there any way to overcome this?

採用された回答

Walter Roberson
Walter Roberson 2013 年 8 月 9 日
If you pass a vector of graphic handles as the first parameter to legend(), then the legend box produced will reflect those handles. When the handles are of line() or lineseries() objects (such as plot() produces), then legend() will use the line color and line appearance and line marker shape and color, to create the line used in the legend box.
  2 件のコメント
Art
Art 2013 年 8 月 12 日
so, using this technique, if I have ten lines plotted, 5 being from set 1 and plotted blue, the other 5 from set 2 plotted red, can I have a legend with only 2 entries, Set 1 and Set 2, with the correct colors? When I try to use h1 = plot(set 1) and h2 = plot(set 2), then combine the handles to a legend, it gives me set 1 as blue and set 2 as blue as well.
Art
Art 2013 年 8 月 13 日
Oh, OK. My format was wrong. This works perfectly. Thanks W.

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

その他の回答 (0 件)

カテゴリ

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