2012-07-19 41 views
2

我使用的是plot(X),其中X是一个n×k的矩阵,它产生k点和n点。在MATLAB中处理多个图

如何显示此图的图例?更重要的是,有没有简单的方法来显示复选框来显示或不显示某些地块?

回答

1

我认为你可以找到这部分的文档有用。
图形用户界面,显示和图形表格数据
http://www.mathworks.com/help/techdoc/creating_guis/bropmbk-1.html

请使用本机构plot_callback功能tableplot.m文件,以获得一个肮脏实现灵活的传奇。

function plot_callback(hObject, eventdata, column) 
% hObject  Handle to Plot menu 
% eventdata Not used 
% column  Number of column to plot or clear 

colors = {'b','m','r'}; % Use consistent color for lines 
colnames = get(htable, 'ColumnName'); 
colname = colnames{column}; 
lgidx = get(haxes, 'UserData'); 
if isempty(lgidx) 
    lgidx = false(size(colnames)); 
end 

if get(hObject, 'Value') 
    % Turn off the advisory text; it never comes back 
    set(hprompt, 'Visible', 'off') 
    % Obtain the data for that column 
    ydata = get(htable, 'Data'); 
    set(haxes, 'NextPlot', 'Add') 
    % Draw the line plot for column 
    hplot = plot(haxes, ydata(:,column),... 
      'DisplayName', colname,... 
      'Color', colors{column}); 
    lgidx(column) = true; 
else % Adding a line to the plot 
    % Find the lineseries object and delete it 
    hplot = findobj(haxes, 'DisplayName', colname); 
    lgidx(column) = false; 
    delete(hplot); 
end 
if any(lgidx) 
    legend(haxes, colnames{lgidx}); 
else 
    legend(haxes, 'off') 
end 
    set(haxes, 'UserData', lgidx); 
end 
+0

是否有可能增加一个传说呢?我似乎无法找到 – 2012-07-19 14:56:14

+0

查看答案的更新。 – slitvinov 2012-07-20 17:11:34

1

一个例子:

x = cumsum(rand(100,3)-0.5);   %# three series with 100 points each 
h = plot(x); 
legend(h, {'first' 'second' 'third'}) 

screenshot