How to place axes objects on top of a figure in MATLAB? - matlab

I'm now using MATLAB R2012b. I want to draw a grey rectangle together with the axes, and want the rectangle to be behind the axes. I tried
uistack(gca,'top');
but nothing happens.
In this article they mentioned that
However, it is possible to place axes objects on top of UIPANEL
objects (which were introduced in MATLAB 7.0 (R14)).
So I think there should be some way to do that.

Try the following:-
set(gca, 'Layer', 'top')
Ref: Draw Matlab graphs with frame, ticks, on top of graph lines

Related

how to display the axes outline when using patch to draw a simple rectangle?

I'm trying to draw a simple rectangle in matlab with the patch function. The thing is that once I use the patch function the outline box disapear (It seems to ignore the current axes in the figure). This is the simple code I'm using:
figure
set(gca,'visible','on')
axis([0,20e9,0.25,1.1])
patch([7e9 7e9 10e9 10e9],[.55 .35 .35 .55],'c','FaceAlpha',0.2,'linestyle','--','edgecolor','b','EdgeAlpha',.2,'linewidth',2);
box on
thanks in advance, I'm using the 2013 version of matlab by the way.
So the issue is that since your patch has transparency, MATLAB must change your figure's renderer from the default renderer to OpenGL (which supports transparency). As a result, some features of your graphics (in your case the bounding box on the axes) may appear differently.
If you change the Renderer back to 'painters', you'll see that the box goes back to the way you expect but you lose transparency.
set(gcf, 'Renderer', 'painters')
Unfortunately, there's really no good solution to this. You could consider changing your face color to appear to be transparent but not really and then MATLAB can use the default renderer. You could also try to increase the LineWidth of the axes
set(gca, 'LineWidth', 2)

Default display of axes in Matlab Gui

I tried using axes for displaying images in Gui.But, before displaying any images, the axes is shown with a plot figure while running the GUI, something like below.
You can see the default axes being displayed. Is there a way to display the axes in running GUI without displaying these plot figures? So that when the image is not displayed in the axes, nothing is displayed. Thanks in advance.
UPDATE 1
I have used 9 axes here, thus the long trail of y axis.
Yes, you can use
axis off
To remove the axes from the empty plots. Then use
axis on
When you actually plot something to bring them back.
Best,

How do you fix the size of an axes graphic object?

I'm creating a simple GUI in MATLAB and I'm trying to create a figure that contains a 2d plot on an axes, all is working well, but I have a rough time trying to figure out how to fix the position of the axes/plot.
The axes seems to scale with the figure window size. If I maximize the figure on my screen, the axes is maximized within, etc. What I want to accomplish is to have a row of buttons beneath the plot on the same figure as the plot, basically an area of 50 (ish) pixels tall that the plot does not encroach on. I know how to do this in HTML, but I can't figure out a good way in MATLAB.
Any alternative approaches would also be greatly appreciated.
Change the units of the axes to anything other than 'normalized', like 'pixels'. Then it won't automatically resize with the figure. From this documentation page:
When you create a graph, MATLABĀ® creates an axes to display the graph. The axes is sized to fit in the figure and automatically resizes as you resize the figure. MATLAB applies the automatic resize behavior only when the axes Units property is set to normalized (the default).
Use set(gca,'Position',pos) where pos = [x y w h] to set the position and size of the axes in the units you chose.
See this answer for an example and a function for holding an axis size once you have it in place.

MATLAB Graphing plots with axes

I have been trying to Create a program with the GUI in MATLAB. When I try to plot information with AXES I can not figure out how to do it. I know about the function plot, but I need to be able to re-size and move the plot around in the figure so I can make room for the input uicontrol. I am not sure what to do. Please help.
There are a couple of different ways to tackle this problem. But the way I always choose to do so, is:
hold on:
plot(...), xlim([xmin xmax), ylim(ymin ymax])
This should set your bounds on the axis.
I don't have Matlab at hand right now, but try the following:
To set size of the plot axes inside the figure window use
set(gca,'Position',[left bottom width height])
see Mathworks' site on axes properties

Draw Matlab graphs with frame, ticks, on top of graph lines

Consider something like
figure
plot(sin(0:0.01:pi))
axis tight
set(gca,'box','on','ticklength',[0.02 0.05])
then export the graph to PDF or whatever. The lines of the graph are on top of the tick labels and the axes. (Furthermore, the lines of the axes don't meet correctly, but that's another story.)
Is there a way (that can be automated) to have the axes drawn on top?
Try:
set(gca, 'Layer','top')
according to the documentation page:
Layer
{bottom} | top
Draw axis lines below or above graphics objects. Determines whether
to draw axis lines and tick marks on
top or below axes children objects for
any 2-D view (for example, when you
are looking along the x-, y-, or
z-axis). Use this property to place
grid lines and tick marks on top of
images.
and to visually see the effect (zoomed in 1200%), I save the figure as a PDF file:
Default (Layer=bottom):
with Layer=top: