How can I position a 2D surface plot within a figure window?

1 次查看(过去 30 天)
Hi all,
I'm trying to align the plot window with the bottom of the figure window. In the first image below, I have exactly what I want to have. However, I would also like to add a title above this image, but when I expand the figure window to allow space for this, the plot becomes unaligned with the figure window. The commands I'm using for figures are (apologies for potentially bad code, I'm far from strong with MATLAB):
fig_i = figure(figurecount);
set(fig_i,'Position',[1000 150 750 850]);
plot3([0.95*xnm - rscalebarlength; 0.95*xnm],[0.05*ynm; 0.05*ynm],[1,1], ...
'LineWidth',5,'Color','w') % Creates a scale bar 1/5 the size of the image rounded to the neaerest 20nm point
hold on
title(['Current at ',closest_v,' mV'],'FontSize',20)
set(0,'defaultaxesposition',[0 0 1 1]);
text(0.95*xnm,0.08*ynm,1,strcat(rscalebarlengthstr,' nm'), ...
'HorizontalAlignment','right', ...
'FontSize',24,'FontWeight','bold', ...
'Color','w','Interpreter','latex') % Creates text right aligned with the scale bar
h = surf(X,Y,current{ind,1});
set(h,'LineStyle','none');
axis equal
axis off
view(0,90);
colormap(cm_viridis);
cbr = colorbar('Box','on','LineWidth',5,'position',[0 0 0.05 0.40]);
set(cbr,'YTick',[]);
hold off
Any help would be much appreciated! Pictures here:
  1 个评论
Nagarjuna Manchineni
Can you also attach a mat file that contains all the data required to run the MATLAB script in the description?
From the static code analysis, I see that you are using a fixed layout with fixed position for all the UI controls (including colorbar). Also, you are creating a text control at the top of the figure that extends the height of the figure further. The issue you are facing could be occurring because of this. For example, you have used the position [0 0 0.05 0.40] for colorbar and [0 0 1 1] for default axes position. These will stay normalized and scale accordingly if you set the 'units' property of the figure to 'normalized'. So, change the position properties of the controls in such a way that they align in the same way at bottom and height.
See the following link for more information on using the 'position' and 'units' properties of the UI controls:

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by