2015-05-26 84 views
1

下面是解决方案!向图上的数据点添加额外信息

enter image description here

这(X,Y)值实际上相当于吨价,这是我想看到的情节。我能做什么?

显然MATLAB在数据点框中显示多个信息的能力:

enter image description here 只是把它作为 “TimePlot(X,Y,T)”,它会工作。我相信这个代码也说明了修改数据提示的几个关键点。

function TimePlot(varargin) 
 
x=varargin{1}; 
 
y=varargin{2}; 
 
t=varargin{nargin}; 
 
fh=figure; 
 
plot(varargin{1:nargin-1}) 
 

 
function output_txt = myfunction(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'); 
 

 
ind=intersect(Find(x,pos(1),1e-10),Find(y,pos(2),1e-10)); 
 
if(length(ind)~=1) 
 
    text='err'; 
 
else 
 
    text=num2str(t(ind),4); 
 
end 
 

 
output_txt = {['X: ',num2str(pos(1),4)],... 
 
    ['Y: ',num2str(pos(2),4)],['T: ',text]}; 
 

 
% 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 
 

 
end 
 

 
dcm=datacursormode(fh); 
 
datacursormode on 
 
set(dcm,'updatefcn',@myfunction) 
 

 

 

 
end 
 

 
function [ out ] = Find(vector, value ,precision) 
 

 
if nargin < 3 
 
    precision = 0.0001; 
 
end 
 

 
out=[]; 
 

 
for i=1:length(vector) 
 
    
 
    if(abs(vector(i)-value)<precision) 
 
     out=[out i]; 
 
    end 
 

 
end 
 

 
end

+0

请你想如何做到这一点更为具体。如果您有更具体的编码问题,请编辑您的问题。否则,它是关于StackOverflow的话题(你可能会在SuperUser上获得帮助) – ryanyuyu

+1

[**这是一个关于如何做这个**的教程](http://blogs.mathworks.com/videos/2011/ 19分之10/教程如何对化妆一个定制数据-踩加速器踏板与Matlab /)。 – thewaywewalk

+1

或cunsult这个重复的问题[数据提示定制在matlab图](http://stackoverflow.com/questions/12100086/data-tip-customization-in-matlab-figure) – thewaywewalk

回答

1

在MATLAB中,您可以找到关于如何创建自定义数据提示的广泛视频教程:Tutorial: How to make a custom data tip in MATLAB

如果您在MATLAB中使用标准数据提示,它将注释数据点的X和Y值。该视频将展示如何自定义该数据提示中显示的信息。

documentation about the datacursormode你会发现更多的一些例子(全部来自文档复制以下):

这个例子能够在目前的数字数据光标模式,并设置 数据光标模式选项。下面的语句

  • 创建一个图表
  • 切换数据光标模式对
  • 获取数据光标模式对象,指定数据提示选项,并获得数据提示占据了线的手柄:
fig = figure; 
z = peaks; 
plot(z(:,30:35)) 
dcm_obj = datacursormode(fig); 
set(dcm_obj,'DisplayStyle','datatip',... 
    'SnapToDataVertex','off','Enable','on') 

disp('Click line to display a data tip, then press Return.') 
% Wait while the user does this. 
pause 

c_info = getCursorInfo(dcm_obj); 
% Make selected line wider 
set(c_info.Target,'LineWidth',2) 

enter image description here

本示例说明如何自定义数据光标 显示的文本。例如,您可以使用Time:和Amplitude:通过创建 简单的更新函数来替换数据提示和数据窗口(x:和y :)中显示的文本 。

在运行它们之前,将以下函数保存在当前目录或MATLAB路径中任何可写的 目录中。因为它们是 函数,所以不能突出显示它们,然后评估选择 以使它们起作用。

将此代码另存为doc_datacursormode。米:

function doc_datacursormode % Plots graph and sets up a custom data tip update function 
fig = figure; 
a = -16; 
t = 0:60; 
plot(t,sin(a*t)) 
dcm_obj = datacursormode(fig); 
set(dcm_obj,'UpdateFcn',@myupdatefcn) 

保存以下代码作为myupdatefcn.m的MATLAB的路径:

function txt = myupdatefcn(empt,event_obj) % Customizes text of data tips 

pos = get(event_obj,'Position'); txt = {['Time: ',num2str(pos(1))],... 
      ['Amplitude: ',num2str(pos(2))]}; 

要设置和使用更新功能,类型:

doc_datacursormode 

当您使用此更新功能放置数据提示时,它看起来像下图中的 。

enter image description here

0

我不认为你可以看到一个二维图第三个维度的价值。你可以尝试做冲浪(x,y,t)或plot3(x,y,t),这样你可以得到一个三维图,并且具有适当的方向,你可以得到所需的图和所有需要的x,y和t值。