我正在使用 plot(X)
,其中 X
是一个 n×k 矩阵,它使用 生成
点。k
个图n
如何显示该图的图例?更重要的是,是否有一种简单的方法来显示复选框以显示或不显示某些图?
最佳答案
我认为您会发现这部分文档很有用。
显示表格数据并绘制图表的 GUI
http://www.mathworks.com/help/techdoc/creating_guis/bropmbk-1.html
请将此主体用于 tableplot.m
文件中的 plot_callback
函数,以获取灵活图例的脏实现。
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
关于matlab - 在 MATLAB 中处理多个绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11562438/