Define limits of a subplot to fit in one axes widget in GUI

4 views (last 30 days)
hi i have a GUI with only one axes widget that has a defined area on GUI. when i click ion my pushbutton to plot the sublpot with 3 rows and 1 column it plots outside the boundary of the axes widget defined earlier and occupies the space in the gui.
any suggestion on how to make it work properly on the pre-defined dimensions of my gui.
alternatively how can i open this subplot window in a different dialog box...like the figure window...
  1 Comment
karan
karan on 23 Nov 2011
like i defiend it the dimensions to be 10 X 10n but the subplot is opening on the dimesions of the GUI i.e 50 x 10

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 24 Nov 2011
subplot() is relative to a figure, not to an axes. You cannot use subplot() to partition an axes: if you try then subplot() will delete the existing axes so that there are no overlaps.
If you want to plot on different within a particular rectangular subsection of a figure, consider creating a uipanel() around the area to be plotted in. You can then subplot() within the uipanel, by specifying the uipanel handle as the Parent property in the subplot() command. For example:
uip = uipanel('Position',[0.75 0.75 0.25 0.25]);
ax1 = subplot(1,3,1, 'Parent', uip);
plot(ax1, x1, y1);
ax2 = subplot(1,3,2, 'Parent', uip);
hist(ax2, x2, y2);
ax3 = subplot(1,3,3, 'Parent', uip);
surf(ax3, z3);
  1 Comment
Thomas Dixon
Thomas Dixon on 18 Feb 2020
I have implemetned you code but i cant get the axis labels and titles to work, I am new to the GUI plots so any comment on my attempt is helpful as such I have included some commnted out ideas I had which you may think will work better.
function [fig] = slidersetup(data_struct,N)
fig = uifigure;
fig.WindowState = 'maximized';
sld_pnl = uipanel(fig,'Position',[10 10 540 50]);
ax_pnl = uipanel(fig,'Position',[10 60 1800 1000]);
val_pnl = uipanel(fig,'Position',[550 10 700 50]);
% ax=uiaxes(fig,'Position',[10 60 400 400])
ax_pnl.AutoResizeChildren = 'off'
%
ax1 = subplot(2,2,[1 2], 'Parent', ax_pnl);
[sx,sy] = meshgrid(data_struct{1}.f_meas(1300:1400),1:N);
set(gcf,'renderer','zbuffer')
s=surf(ax1,sx*10^-9,sy,data_struct{1}.I_f_meas(1300:1400,1:N)'.*10^6);
s.LineStyle = 'none';
s.FaceColor = 'interp';
view([10 -20 20]);
% ax=gca;
% ax.FontSize=22;
xlabel('Frequency (GHz)');
ylabel('Node (N)');
zlabel('Current (uA)');
ax2 = subplot(2,2,3, 'Parent', ax_pnl);
plot(ax2,1:N,data_struct{1}.phase(1,:))
ax3 = subplot(2,2,4, 'Parent', ax_pnl);
plot(ax3,1:N-1,data_struct{1}.phase_diff(1,:),'o')
sld = uislider(sld_pnl,'Position',[10 30 180 3],'ValueChangedFcn',@(sld,event) PlotUpdate(sld,ax_pnl,sld_pnl,data_struct,N));
sld.Limits = [1 200];
sld.Value = 1;
sld.MajorTicks = [1 50 100 150 200]
tbox = uieditfield(val_pnl,'numeric','Position',[550 10 565 40],'ValueChangedFcn',@(tbox,event) numberChanged(tbox,sld,ax_pnl,sld_pnl,data_struct,N));
tbox_val = uieditfield(sld_pnl,'Position',[200 10 215 40],'Value',[num2str(sld.Value),' GHz']);
end
function PlotUpdate(sld,ax_pnl,sld_pnl,data_struct,N)
sld.Value = round(sld.Value);
%set(h, 'YData', data_struct{1}.phase(sld.Value*10,:))
% plot(ax,1:N,data_struct{1}.phase(10*sld.Value,:))
ax2 = subplot(2,2,3,'Parent',ax_pnl);
plot(ax2,1:N,data_struct{1}.phase(sld.Value*10,:));
ax3 = subplot(2,2,4,'Parent',ax_pnl);
plot(ax3,1:N-1,data_struct{1}.phase_diff(sld.Value*10,:),'o');
% val_pnl.Children.tbox.String = [num2str(sld.Value*10),' GHz']
tbox_val = uieditfield(sld_pnl,'Position',[200 10 215 40],'Value',[num2str(sld.Value),' GHz']);
end
function numberChanged(tbox,sld,ax_pnl,sld_pnl,data_struct,N)
sld.Value = tbox.Value;
ax2 = subplot(2,2,3,'Parent',ax_pnl);
plot(ax2,1:N,data_struct{1}.phase(sld.Value*10,:));
ax3 = subplot(2,2,4,'Parent',ax_pnl);
plot(ax3,1:N-1,data_struct{1}.phase_diff(sld.Value*10,:),'o');
% val_pnl.Children.tbox.String = [num2str(sld.Value*10),' GHz']
tbox_val = uieditfield(sld_pnl,'Position',[200 10 250 50],'Value',[num2str(sld.Value),' GHz']);
end
Produces
Where clearly the surf plot axis arentl labelled
I would like to be able to do all the usual stuff I do with plots label, latex style set axis sizes turn grids on/off change the view etc.. is this possible on a UIpanel plot?
You can find the stuff I plot on the repository here:
any help is most welcome

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!