简体   繁体   English

在Matlab指南针图中包括图例

[英]include legend in matlab compass plot

I am using the compass command in matlab to plot wind speeds and direction. 我在Matlab中使用罗盘命令绘制风速和风向。 I would like to alter the default version to (1) remove the labels within the compass, and (2) draw a legend outside the compass plot to demonstrate the magnitude of each arrow. 我想将默认版本更改为(1)删除罗盘内的标签,以及(2)在罗盘图外绘制图例以演示每个箭头的大小。

Specifically, using the compass is it possible to include a legend which describes the magnitude of the arrows instead of having the values defined on the figure? 具体来说,是否可以使用罗盘添加说明箭头大小的图例,而不用在图中定义值? For example: 例如:

rng(0,'twister') % initialize random number generator
M = randn(20,20);
Z = eig(M);

figure
compass(Z)

This is a normal compass plot where the magnitude of each entry is shown by labels on the figure, here they are 1:5. 这是一个普通的罗盘图,其中每个条目的大小均由图中的标签显示,此处为1:5。 I can remove the labels with: 我可以使用以下方法删除标签:

h = findall(gca,'type','text'); % Find all handles to text labels
legit = {'0','30','60','90','120','150','180','210','240','270','300','330','360',''}; % Define what to keep
idx = ~ismember(get(h,'string'),legit); % Take the others and set them to empty string
set(h(idx),'string',''); 

However, I would now like to include a legend which demonstrates the length of an arrow with a size of say 2 would be. 但是,我现在想包括一个图例,该图例显示的箭头长度为2。 Any ideas on how to do this? 有关如何执行此操作的任何想法?

Try some version of this -- after creating the data: 在创建数据后尝试以下版本:

u=abs(Z)
figure(1)
compass(Z)
set(findobj(gcf,'type','text','-and','fontsize',10),'string','')
legend({['z_1 = ',num2str(u(1)),' units'],...
        ['z_2 = ',num2str(u(2)),' units']},...
     'location','southoutside')

I used compass() a lot, but actually i'm not so sure that the font size of the labels are 10, in my (many) compass plots i have used this as a parameter and it worked fine. 我经常使用罗盘(),但是实际上我不确定标签的字体大小是否为10,在我的(许多)罗盘图中,我已将此参数用作参数并且效果很好。 If it don't, just use the parameter text that findobj() will get all of the text in the figure as well. 如果没有,则只需使用参数text,findobj()也会获得图中的所有文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM