How to delete the axes coordinate in Matlab GUI? - matlab

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

Related

Ticks missing in contourf

I want to plot ticks at logarithmic values (without labels, only the ticks). For some reason the following code doesn't plot them (set(gca,'XTick') doesn't do anything):
figure1=figure(1)
axes1 = axes('Parent',figure1,'YScale','log','XScale','log');
grid(axes1,'on');
hold(axes1,'on');
[C,h]=contourf(lamx(2:NKX+1),lamz(2:NKZ+1),phi2d(2:NKX+1,2:NKZ+1)',[10],'LineColor','none');
clabel(C,h);
axis tight;
axis([lamx(end) max(lamx) lamz(end) max(lamz)])
xlabel('\lambda_x','Fontsize',20);
ylab=ylabel('\lambda_z','Fontsize',20);
set(gca,'XTick',0.1:0.1:1)
grid on
set(gcf, 'PaperPositionMode','auto');
set(ylab, 'Units', 'Normalized', 'Position', [-0.1, 0.5, 0]);
set(gca,'linewidth',1.5,'FontSize',16)
colormap(flipud(gray(256)));
colorbar;
print('-dpng','-opengl','-r1200','2dspec')
How could the ticks be plotted?
The ticks in your example are obscured by the Contour object itself. The order in which the Axes elements are drawn relative to objects within it is controlled with the Axes Layer property.
The default value for this property is bottom which means anything like a filled contour drawn in the axes will be drawn on top of the ticks, and you won't be able to see them. The contourf function obviously knows this isn't a helpful default for plots that will obscure the ticks in their entirety because it usually changes the property to top when you call it – but only when the Axes NextPlot is set to replace. By calling hold on you also cause contourf to leave that property alone, so it ends up staying at bottom.
In your example you can deal with this in one of two ways.
As it's currently written, there no intentional effect of the hold(axes1,'on'); line, because you're only adding one plot. So you could just remove that line if your full code doesn't rely on it. Otherwise,
Set the Layer property to top from the outset when you create the axes:
axes1 = axes('Parent',figure1,'YScale','log','XScale','log','Layer','top');

Dynamically plotting multiple plots to be displayed on one set of axes (one plot at a time)

Following this post I have a function that when run, updates 4 plots. This works as expected, except when I go to change which plot is displayed, it looks like there are remnants of the previously displayed plot. I go from a bar graph to a surfc, but I still see the bars across a flat plane. I am currently setting my data and drawing with
set(hplot2, 'yData', ME)
drawnow
Do I need to refresh the axes/plot somehow? I change which plot is on the axes with set(plot1, 'Parent', axes1). I have no idea where is problem is arising.
If you're switching between two plots you will either want to clear the axes prior to plotting the next thing using cla
cla(axes1);
or you will want to simply toggle the visibility of the existing plot objects.
% To show only the bar plot
set(hbar, 'Visible', 'on')
set(hsurf, 'Visible', 'off')
% To show only the surf plot
set(hbar, 'Visible', 'off')
set(hsurf, 'Visible', 'on')
The root of the problem, is that an axes can actually hold many plots, so if you simply create a new plot and assign it as a child to an axes, the other plot objects are still there.
If you are creating entirely new graphics objects every time you plot something (by calling bar or surfc) using cla will be easiest. That being said, if you can adjust your code to simply update existing plot objects, that is ideal from both a performance and graphics management perspective.
Also, as another side note. I would discourage using set(plot1, 'Parent', axes1) after object creation. It is more robust to specify the Parent property directly in the object constructor. This way you ensure that it goes directly to the axes you want.
plot1 = bar(data, 'Parent', axes1);
Edit
Now that I think about it, since you're toggling between 3D and 2D data, it may be easier to simply have two axes at the same location (one for the bar and one for the surf). You would then toggle the visibility of the axes on/off as needed. This way all of your view settings are preserved for a given axes.
barax = axes();
surfax = axes();
% Ensure they are located at the same position
link = linkprop([barax, surfax], 'Position');
hbar = bar(data, 'Parent', barax);
hsurf = surfc(data, 'Parent', surfax);
% Toggle these to switch plots.
set(barax, 'Visible', 'off')
set(surfax, 'Visible', 'on')

How to Control Relative Size of Figures with Colorbar in Matlab?

I am trying to line up a plot of a signal with an image where the image has a colorbar. The colorbar causes the axes to be offset horizontally.
My intuitive approach would be to fix the size of figures to something, like in Gnuplot with papersize. However, not sure which would be the best fit here.
To Adjust Scaling to Square in Full Screen Mode of Matlab?
I want to maintain the relations between the two figures. I cannot use squareform in the first figure for some reason, while I can in the latter figure.
Code
figure
ax2=subplot(2,2,2);
plot(mat2gray(pdist(data, 'correlation')));
title('Corr pdist');
cbar2 = colorbar(ax2);
xlim([0 size(mat2gray(pdist(data, 'correlation')),2)]);
set(cbar2, 'Visible', 'off');
ax4=subplot(2,2,4);
imshow(squareform( mat2gray(pdist(data, 'correlation')), 'tomatrix') );
colormap('parula'); colorbar;
title('Square Corr pdist');
Wrong Scaling in Output when Full Screen Mode of Matlab where you see the colorbar method is not sufficient for holding relations as proposed in the answer here about How to Control Relative Size of Figures with Colorbar in Matlab?
Right Scaling in Output when Default View
How can you maintain the square view of figures in the Full Screen Mode of Matlab?
I would simply create a colorbar for the top axes as well and set the visibility to off.
figure;
ax1 = subplot(2,1,1);
ax2 = subplot(2,1,2);
cbar1 = colorbar(ax1);
cbar2 = colorbar(ax2);
set(cbar1, 'Visible', 'off')
The benefit here is that you will get consistent behavior when resizing the figures, etc. because the size and position of the two axes will be rendered in the same way.
The other thing you will need to remember is to keep the axes the same in all aspects. So for example if you have an image in the bottom axes (using imshow), MATLAB by default sets the axes to a square. To get your top plot to also be square you will need to use axis square. Then they will continue to line up.
axis(ax1, 'square')

Axes takes up entire screen in MATLAB GUI

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')

Overlapping axes in GUI when plotting boxplot in MATLAB

I am creating a GUI in MATLAB using GUIDE. I have several axes, and in one of them I want to draw a boxplot. My problem is that after drawing the boxplot, the size of the axes changes, and it overlaps with some of my other figures.
To replicate this problem, create a .fig file using GUIDE containing two axes: axes1 and axes2, as shown in the figure: .
Then, in the OpeningFcn, add the following lines:
Z = normrnd(1,3,[100,1]);
plot(handles.axes1, Z);
boxplot(handles.axes2,Z)
Then lauch the GUI. I see the following:
As you can see, the two axes overlap. I've tried changing the properties of the box plot, but with no luck.
I use MATLAB 7.10 (R2010a) and Kubuntu 12.10.
It appears that boxplot makes the axes grow wider, not sure why. In any case, saving the axes position right before plotting and resetting it right after seems to work for me:
Z = normrnd(1,3,[100,1]);
plot(handles.axes1, Z);
pos = get(handles.axes2, 'position');
boxplot(handles.axes2,Z);
set(handles.axes2, 'position', pos);
Cheers,
Giuseppe