I have a GUI which has 10 panel in it. My LCD is 20". When I want to see my GUI in my laptop(15.6") I can not see my Panels properly. I have examined all the solutions, but I can not solve this problem.
Can anyone help me?
To resize the figure just change its Position property. The panels will resize according to it, depending on how you specified your panel units. I.e., to maximize a figure:
set(figH,'Units','normalized');
set(figH,'Position',[0 0 1 1]);
In the case you want to specify your figure size as pixel units do:
set(figH,'Units','pixels');
set(figH,'Position',[left_gap_nPixels bottom_gap_nPixels length_nPixels width_nPixels]);
Btw, I haven't mentioned, but figH is your figure (or panel handle, if you want to resize it). You can use gcf if it is your current active handle.
Just as reference, the units you can specify are:
{'inches' 'centimeters' 'characters' 'normalized' 'points'
'pixels'}
Consider checking the figure properties documentation and uipanel properties for more details on the position and units property.
Hope it helps.
Take a look at property Units.
The size of a graphic object may be expressed in pixels, in characters, or better (for you) proportionally to the size of the parent.
If you change the units of the sizes of all the Panels to be proportional to the size of the main window, it will be ok. For the main window, simply use get(0,'ScreenSize'); to get the screen size in pixels.
Related
I want to set the same size for all figures using Matlab in order to save it later. How can I do that?
I thought it would be better to plot a figure first, and then get the size and position using command pos = get(gcf, 'Position'), and set the position for all the other figures.
Is it correct? Any better approaches?
There are a lot of options of how to save a figure in Matlab. If you do not use a Save As dialog box, you have two functions to choose from: saveas and print.
'Position' defines location and size of the drawable area, specified as a vector of the form [left bottom width height]. This area excludes the figure borders, title bar etc. Right now you are basically getting the size and location of your first figure as it appears on screen and save based on these dimensions.
When saving your figures this way, the dimensions will correspond to whatever internally was defined in Matlab or you yourself redefined using 'Position' property. But you don't always want/need the size of the saved figure and the size of the figure as it appears on screen to be the same. And you also have to take care of the position of your figures, which is in your case you retrieved using a set function, I'll skip it in my example.
gcf=figure;
figure_width_to_save = 12.5; %cm
figure_height_to_save= 10; %cm
location_x=2; %cm
location_y=2; %cm
gcf.Units = 'centimeters';
gcf.Position = [location_x location_y figure_width_to_save figure_height_to_save];
saveas(gcf,[savefigures_path,savefigure_name,'_saveas.tiff'],'tiffn');
print(gcf, '-dtiffn', [savefigures_path,savefigure_name,'_print.tiff'], '-r300');
But it's better to have a separate control over the settings used for saving a figure. For that you have to define 'PaperPosition' property. 'PaperPosition' defines figure size and location on page when saving, specified as a four-element vector of the form [left bottom width height], but actually with 'PaperPosition' property you don't need to think about the location of your figure as much as you would with the 'Position' property.
Now about the saving itself, you didn't mention which approach you use though.
The saveas function uses a resolution of 150 DPI and uses the 'PaperPosition' and 'PaperPositionMode' properties of the figure to determine the size of the image. If you want to print or save figures that are the same size as the figure on the screen, ensure that the 'PaperPositionMode' property of the figure is set to 'auto', but I prefer to have control over these properties myself.
If you save your figure in Matlab with saveas, then as an example you need to specify this:
gcf.PaperPositionMode = 'manual';
gcf.PaperUnits = 'centimeters';
gcf.PaperPosition = [0 0 figure_width_to_save figure_height_to_save];
saveas(gcf,[savefigures_path,savefigure_name,'.tiff'],'tiffn');
Function print additionally allows you to have control over the saved resolution of the figure. For example, a flag '-r300' sets the output resolution to 300 dots per inch. To specify screen resolution, use '-r0'.
print([savefigures_path,savefigure_name,'.tiff'],'-dtiffn','-r300')
Check out Matlab's examples about saving figures at specific size and resolution
I have a trivial question but not able find a effective solution. I hope somebody could help me in this regard.
I currently have 4 different axes in a GUI. ax1(top left) and ax4(bottom left) should be aligned vertically and similarly ax2(top right) and ax4(bottom right) should be aligned vertically. (I have attached a sample image)
ax1 and ax2 are used to show images that are usually larger in size(~512x512) and ax3 & ax4 are used to display images of size ~43x512. Even though I created the axes with x-axis the same size when I display images they change size and not aligned anymore. No matter what images I display, I want the top and bottom images to of same x length and aligned always.
I tried to keep the XLim the same; XData the same but still doesnt work.
Any help is greatly appreciated.
Thanks, Bala
You can use the align function which is used to do just that. The calling syntax is as follows:
align(HandleList,'HorizontalAlignment','VerticalAlignment')
Therefore in you case, you could write something like this (Note that you wrote ax4 twice in your question, I guess you wish to align axes 1-3 and 2-4):
align([handles.ax1 handles.ax3],'VerticalAlignment','none', 'HorizontalAlignment','center')
and likewise for the other 2 axes:
align([handles.ax2 handles.ax4],'VerticalAlignment','none', 'HorizontalAlignment','center')
I am currently writing up a scientific thesis and am very desparate about creating figures that have the exact dimensions I want them to have. Especially the font sizes do not match.
I already googled alot and there are a bunch of guides and scripts about this topic but nothing really helped - I have not yet figured out (sorry) why my approach does not work:
FS=8; %font size in points (the same as in my document)
width=12; %width of figure in cm
height=4; %height of figure in cm
scatter(1:20,rand(20,1));
xlabel('X','fontsize',FS),ylabel('Y','fontsize',FS),title('X vs. Y','fontsize',FS)
%now I scale the figure and place it in the bottom left corner. The white margins around it are cropped automatically
set(gca,'units','centimeters','outerposition',[0 0 width height])
%export as .eps
print(gcf,'-depsc','test')
When I load test.eps into Inkscape, the figure is 10.16 x 3.529 cm large and the font sizes (of title and axis labels) are 10.
How do I get a figure with the exact scaling, especially regarding the font size?
I did the following:
FS=8; %font size in points (the same as in my document)
width=12; %width of figure in cm
height=4; %height of figure in cm
scatter(1:20,rand(20,1));
set(gca, 'fontsize', FS);
xlabel('X','fontsize',FS),ylabel('Y','fontsize',FS),title('X vs. Y','fontsize',FS)
set(gcf,'units','centimeters','position',[0 0 width height])
export_fig(gcf, 'test.pdf', '-transparent', '-nocrop')
The output figure is 12cm x 4cm. The font size still claims to be 10 in Inkscape, however, but it looks the same size as that in the figure. Export_fig can be downloaded from the MATLAB file exchange.
Here is how I solve it as of now - it is not exactly elegant but it works...
I plot my figure and arrange and scale it in the figure window the way I want it to be scaled:
set(gcf,'units','centimeters','position',[0 0 width height])
Due to the white margins around the axes, I increase the width/height by approximate (trial and error...) values that the margins use up. I then export it:
export_fig(gcf,'test','-eps','-transparent')
And load it into Inkscape. Now I set the document properties so that the document has the exact size I want my figure to have - the figure is partly out of this frame because I increased the width/height earlier.
Then I arrange the axes to have as much white space between them as I want them to have; hopefully, everything is inside the document borders after that.
Probably the drawing is smaller than the document borders now - to ensure that it will not get expanded, messing up the scaling, when I put it in my actual document (my thesis, not the Inkscape document...), I simply create a white background that matches the document borders. Aaand done.
Except for the fontsize and fontname properties in Matlab - I have not figured out why they are not properly exported...but this is not hard to manually fix in Inkscape.
Thanks for your help, everyone.
Does any one here have an idea about how to change the position of output in the GUI matlab to be to the right side of the box and not in the center ?
i think I have to change some properties of the result text box
Check this post out: Positioning of figures
The figure Position property controls the size and location of the figure window on the screen. Monitor screen size is a property of the root Handle Graphics object. At startup, the MATLAB software determines the size of your computer screen and defines a default value for Position. This default creates figures about one-quarter of the screen's minimum extent and places them centered left to right, in the top half of the screen.
The Position Vector
MATLAB defines the figure Position property as a vector. So you may use a figure and text into it, e.g.
figure(gcf)
text(offsetX1, offsetX1, ['result 1: ' num2str(result1)])
text(offsetX2, offsetX2, ['result 2: ' num2str(result2)])
Displaying analytical results in a MATLAB GUI
This post talks about adding a static textbox with your results and positioning it.
Move GUI figure to specified location on screen:
Syntax:
movegui(h,'position')
movegui(position)
movegui(h)
movegui
The answer is pretty much trying to cover up the vauge nature of the question
I saw many Q&A here about squeezing space out of Matlab figures. However I want to squeeze space resulted from a possibly fixed aspect, i.e. to choose proper paper size for figure printing when aspect is fixed.
Quite often I work with DEM/map/image thus I use axis image. Now if I want to produce a high resolution image I do something like
set(gcf,'PaperUnits','inches','PaperPosition',[0 0 4 3])
print('-dpng','-r300','somefile.png')
as described in Matlab KB.
The problem here is to determine a proper aspect such that I can specify proper paper size that would leave no white/background stripes on either sides.
Apparently if I have a map (let's say 1000x2000 cells) with aspect ratio of 0.5, and I'm printing it on 4"x3" paper, I'll get background stripes on the sides. This is quite annoying as I'd prefer 1.5"x3" paper + axes & labels or so. Right now I have to manually adjust paper size.
This is inconvenient as I'd like a universal solution. For instance I may print a plot into file that I expect to occupy 4"x3" as well that has no fixed aspect. Or I may want to print a 3D figure. I'm aware of daspect and pbaspect, but how can I know how it is currently drawn?
Perhaps I can derive current 2D aspect from get(gca,'Position') and then scale it to my maximum allowed desired size (e.g., 4"x3") while respecting whether DataAspectRatioMode (?) property is set to manual. Is it the way to proceed or is there a better way?
I am not exactly sure if I understand your problem exactly, but I have used the following commands to create pdf images that are sized exactly to the size of the figure. I have used this for both 2D and 3D figures. The "handle" variable is simply your figure handle.
set(handle,'Units','inches');
set(handle,'PaperUnits','Inches','PaperPositionMode','auto');
P = get(handle,'Position');
set(handle,'PaperSize', [P(3),P(4)]);