在MATLAB中处理多个图

时间:2012-07-19 13:56:19

标签: matlab plot

我正在使用plot(X)X是一个n-by-k矩阵,可生成kn点。

如何显示此情节的图例?更重要的是,是否有一种简单的方法来显示复选框以显示或不显示某些图?

2 个答案:

答案 0 :(得分:1)

我认为您可以发现本文档的这一部分很有用 显示和绘制表格数据的GUI
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

答案 1 :(得分:1)

一个例子:

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

screenshot