Axes takes up entire screen in MATLAB GUI - matlab

There must be a simple answer to this. I cannot really find a suitable response after a lot of searching.
This is what I want to make using the GUIDE tool.
This is what I get. (Note: the plot is made using the subplot function)
What am I doing wrong? Shouldn't the plot simply fit into the predefined 'axes1' rectangle from the GUIDE interface?

The way I solved this is by putting the axes in a separate panel, thus restraining them to the size of the panel. Hope it helps!
PS: I am using subplot too.

If you use the subplot function within the GUI it will override the axes defined using GUIDE. Instead it is best to plot two separate axes.
%this will plot axes 1
axes(handles.axes1)
plot(x,y)
title('Title of Axes 1'
ylabel('y Label of Axes 1')
xlabel('x Label of Axes 1')
%this will plot axes 2
axes(handles.axes2)
plot(x,y)
title('Title of Axes 2'
ylabel('y Label of Axes 2')
xlabel('x Label of Axes 2')

Related

Plotting in GUI of Matlab

Until now i had only 1 axis in my GUI to I used to just plot directly using plot command. Plus i need to plot these in a loop.
for i = 1:length(sig)
plot(sig(i).time,sig(i).signal,sig(i).time,updated(i).filter,)
hold on
end
Now i have 2 axes in my GUI, how can I make a certain plot appear in 1st axis and another in my 2nd axis
Now for example i need to plot the below in the 2nd axis
for i = 1:length(sig)
plot(sig(i).time,sig(i).fil,sig(i).time,updated(i).sig,)
hold on
end
Any help will be appriciated
You could specify the axes for hold and plot functions. Considering you have two axes, h1 and h2 inside your figure, you could do the following:
hold(h1, 'on')
hold(h2, 'on')
for i = 1:length(sig)
plot(h1, sig(i).time,sig(i).signal,sig(i).time,updated(i).filter)
plot(h2, sig(i).time,sig(i).fil,sig(i).time,updated(i).sig)
end

Plotting an axis on a scatter3 figure

Hello I would like to display an axis centered on [0,0,0] of a scatter 3 plot.
Is there a way to do this using the line function?
http://au.mathworks.com/help/matlab/ref/line.html
Not quite sure how to interpret it. Would greatly appreciate a hand.
If you just need the axes try adding:
hold on;
line(xlim,[0,0],[0,0]);
line([0,0],ylim,[0,0]);
line([0,0],[0,0],zlim);
After your scatter plot.
EDIT:
If you want to place the axes with origin at another point, you can do as follows:
hold on;
line(xlim,[origin(2),origin(2)],[origin(3),origin(3)]);
line([origin(1),origin(1)],ylim,[origin(3),origin(3)]);
line([origin(1),origin(1)],[origin(2),origin(2)],zlim);
Where origin is the point where you want the axes to meet.

Heatmap plots extra axes

I'm using the heatmap function in Matlab to plot some maps, the maps themselves are fine but the program seems to be adding extra borders and axes onto the figures, no idea why this is happening!
My code is:
figure(1)
hFig = figure(1);
set(gcf,'PaperPositionMode','auto')
set(hFig,'Position',[1000 1000 900 800])
colormap('hot');
imagesc(data)
xlabel('X({\mu}m)')
ylabel('Y({\mu}m)')
Here is an image of what I mean by extra axes:
Thanks!
Edit1: Here is the image after the first proposed fix:
Remove the xlabel and ylabel from the last lines of your code. Since you have already used the set function you can integrate them directly by doing
imagesc(data);
colomap('hot');
set(gca,'Xtick',[0:5:50],'XtickLabel',[0:5:50]);
set(gca,'Ytick',[0:5:50],'YtickLabel',[0:5:50]);
colorbar('YtickLabel',{'1000','900','800'});

How to delete the axes coordinate in Matlab GUI?

I want to make a Matlab GUI program.
When i use the axes to display the image, there are the axes number around the axes.
How to delete it?
so my GUI program will display the axes without any coordinates around the axes.
here is my code for display an image in axes.
axes(handles.axes16);
handles.image_gray = image_gray;
imshow(image_gray);
guidata(hObject, handles);
And here is the axes coordinates that i meant.
Remember that the axes is an handle object with many properties. I would recommend setting the axes properties 'xtick', and 'ytick', to an empty array. That way, you preserve the border, and background color of the axes. Simply turning the axes off will make your lines render on top of the background figure, which may or may not be the effect you are looking for.
Example:
set(handles.axes16,'xtick',[],'ytick',[])
A quick way to turn off the axis is, well, axis off:
Example
figure;
plot([-10:10],randn(21,1));
xlabel('x');
ylabel('y');
Now turn axis off:
axis off

MATLAB - How to zoom subplots together?

I have multiple subplots in one figure. The X axis of each plot is the same variable (time). The Y axis on each plot is different (both in what it represents and the magnitude of the data).
I would like a way to zoom in on the time scale on all plots simultaneously. Ideally by using the rectangle zoom tool on one of the plots, and having the other plots change their X limits accordingly. The Y limits should remained unchanged for all of this. Auto fitting the data to fill the plot in the Y direction is acceptable.
(This question is almost identical to Stack Overflow question one Matplotlib/Pyplot: How to zoom subplots together? (except for MATLAB))
Use the built-in linkaxes function as follows:
linkaxes([hAxes1,hAxes2,hAxes3], 'x');
For more advanced linking (not just the x or y axes), use the built-in linkprop function
Use linkaxes as Yair and Amro already suggested. Following is a quick example for your case
ha(1) = subplot(2,1,1); % get the axes handle when you create the subplot
plot([1:10]); % Plot random stuff here as an example
ha(2) = subplot(2,1,2); % get the axes handle when you create the subplot
plot([1:10]+10); % Plot random stuff here as an example
linkaxes(ha, 'x'); % Link all axes in x
You should be able to zoom in all the subplots simultaneously
If there are many subplots, and collecting their axes handle one by one does not seem a clever way to do the job, you can find all the axes handle in the given figure handle by the following commands
figure_handle = figure;
subplot(2,1,1);
plot([1:10]);
subplot(2,1,2);
plot([1:10]+10);
% find all axes handle of type 'axes' and empty tag
all_ha = findobj( figure_handle, 'type', 'axes', 'tag', '' );
linkaxes( all_ha, 'x' );
The first line finds all the objects under figure_handle of type "axes" and empty tag (''). The condition of the empty tag is to exclude the axe handles of legends, whose tag will be legend.
There might be other axes objects in your figure if it's more than just a simple plot. In such case, you need to add more conditions to identify the axes handles of the plots you are interested in.
To link a pair of figures with linkaxes use:
figure;imagesc(data1);
f1h=findobj(gcf,,’type’,’axes’)
figure;imagesc(data2);
f2h=findobj(gcf,,’type’,’axes’)
linkaxes([f1h,f2h],’xy’)