matlab 箭头 类型,MATLAB分散工具提示,显示其他类型的数据和带箭头的连接点

答案1

一种解决方案是为data-tooltip定义自己的回调函数.要做到这一点,首先需要在图中保存名称.我们可以使用UserData属性:

% modify the end of your code to:

gsh = gscatter(xData',yData',group');

Names = [LionNames WolfNames];

set(gsh,{'UserData'},{Names});

接下来,我们创建以下回调函数(我使用了Matlab的defualt并对其进行编辑),并将其保存在新的m文件中:

function output_txt = tooltip_callback(obj,event_obj)

% Display the position of the data cursor

% obj Currently not used (empty)

% event_obj Handle to event object

% output_txt Data cursor text string (string or cell array of strings).

pos = get(event_obj,'Position');

output_txt = {['X: ',num2str(pos(1),4)],...

['Y: ',num2str(pos(2),4)],...

event_obj.Target.UserData{event_obj.Target.XData==pos(1)}}; %

% If there is a Z-coordinate in the position, display it as well

if length(pos) > 2

output_txt{end+1} = ['Z: ',num2str(pos(3),4)];

end

现在我们点击图中的一个工具提示,然后选择Select Text Update Function:

6787a8e576e52c3da3d2fbc5546c3142.png

从浏览器中我们选择我们保存的回调函数.

结果:

Qd44t.png

以同样的方式,您可以根据需要将日期添加到工具提示中,或者使用我对Q2的回答…

答案2

以下是如何使用annotations执行此操作的方法:

ax = axes; % create the axis

% plot all lines (no need for the loop) so we can put the legend after:

p = plot(day1Lions,day2Lions,'-');

legend('Tyrion','Jamie','Cersei')

% get the lines colors:

col = cell2mat(get(p,'Color'));

% loop through the arrows:

for k = 1:size(day1Lions, 2)

% get the data coordinates:

x = day1Lions(:,k);

y = day2Lions(:,k);

pos = ax.Position;

% convert them to normalized coordinates:

% white area * ((value - axis min) / axis length) + gray area

normx = pos(3)*((x-ax.XLim(1))./range(ax.XLim))+ pos(1);

normy = pos(4)*((y-ax.YLim(1))./range(ax.YLim))+ pos(2);

% plot the arrow

annotation('arrow',normx,normy,'Color',col(k,:))

end

结果:

zswdi.png

您还可以设置原始行不可用,具有:

set(p,{'Visible'},{'off'})

但它会将传说文字变成灰色,无论如何它们完全被箭头所覆盖.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值