简体   繁体   中英

include legend in matlab compass plot

I am using the compass command in matlab to plot wind speeds and direction. 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.

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. 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. 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. If it don't, just use the parameter text that findobj() will get all of the text in the figure as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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