Skip empty array in plot legend?
6 ビュー (過去 30 日間)
古いコメントを表示
I'm using logical arrays to plot various levels of threshold excedance.
How can I skip legend titles of empty arrays? In the following screenshots you'll see all levels of threholds exceeded, next you will see where only low level of thresholds are exceeded. and the legend is incorrect. As a note on the second figure, the yellow dots shold be "exceeds construction lims".
The bottom plots legend should have "exceeds constuction lims" instead of "Level1"
I'm assingin variable names to each plot and using hold on. Simplified example code:
a = plot(the blue line);
b = plot (logical array of level 1);
c = plot(logical array of level 2);
d = plot(logical array of exceeds construction lims);
legend([a b c d], {'blue line', level1', 'level2', 'exceed const lims'});
I need to be able top skip level1 and level2 if they are 0x1 empty arrays.
I cannot simply change the order because for somethings I do not have constuction limits so I would run into the ame issue by just reordering my plots.
0 件のコメント
回答 (2 件)
Adam Danz
2019 年 4 月 12 日
編集済み: Adam Danz
2019 年 4 月 12 日
Try this.
% List all possible legend handles and their strings
legHands = {a b c d};
legStrs = {'blue line', level1', 'level2', 'exceed const lims'};
% Determine which handles aren't empty
hasData = ~cellfun(@isempty, legHands);
% Produce legend, ignore empties
legend([legHands{hasData}], legStrs{hasData})
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!