Adding a Graph into a uipanel GUI
48 次查看(过去 30 天)
显示 更早的评论
I am trying to add a graph into a uipanel that I have on my matlab GUI. I have a pushbotton that intakes information from empty text boxes and then after I use the push botton it makes a graph. I want to have this graph appear on my uipanel rather than a second window, is that possible or would I have to use a axis? I was planning on having adding a map into that panel as well, but later on.
0 个评论
回答(1 个)
Thomas Satterly
2019-12-6
You need to create an axis object where the data will be plotted and pass this axis as the first argument to your plot function.
% Create a figure
fh = figure();
% Create a panel to hold the plot axis
axisPanel = uipanel(fh, 'Position', [0 0 0.5 1], 'BackgroundColor', [1 1 1]);
% Create a new axis on the panel
leftAxis = axes(axisPanel, 'Position', [0.1 0.1 0.8 0.8]);
% Create a different panel to hold the button and a second axis
buttonPanel = uipanel(fh, 'Position', [0.5 0 0.5 1], 'BackgroundColor', [0.7 0.7 0.7]);
% Create an axis on the right panel
rightAxis = axes(buttonPanel, 'Position', [0.1 .3 0.8 0.6]);
% Create pushbuttons to plot data
leftPlotButton = uicontrol(buttonPanel, 'Style', 'pushbutton', ...
'String', 'Plot Left', 'Units', 'normalized', 'Position', [0.1 0 0.3 0.1], ...
'Callback', @(src, event) buttonPressCallback(leftAxis));
rightPlotButton = uicontrol(buttonPanel, 'Style', 'pushbutton', ...
'String', 'Plot Right', 'Units', 'normalized', 'Position', [0.6 0 0.3 0.1], ...
'Callback', @(src, event) buttonPressCallback(rightAxis));
function buttonPressCallback(thisAxis)
% Plot on the specified axis
plot(thisAxis, rand(1, 10), rand(1, 10), 'r.');
end
It's also possible to create the graphics object itself (e.g. 'matlab.graphics.chart.primitive.Line') and set the 'Parent' property to the axis you want it to appear on, rather than use a 'plot'-style command
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!