How do I hide axes and ticks in matlab without hiding everything else - matlab

I draw images to axes in my matlab UI, but I don't want the axes and ticks to be visible how do I prevent that, and also where do I make this call?
I do this
imagesc(myImage,'parent',handles.axesInGuide);

axis off;
Is this what you are looking for?
This is definitely somewhere else on this website and in the matlab documentation. Try typing
help plot
Or using the documentation on plotting!
edit: Now that you have shown what you are doing. (You don't need the handles, I just always write them in to clutter my workspace)
myImage = yurbuds0x2Dironman; # don't ask
fH = figure;
iH = imagesc(myImage);
set(gca,'xtick',[],'ytick',[])
Are you able to do it like this?

I support the
set(gca,'xtick',[],'ytick',[]);
approach over the
axis off
one. The reason is set(gca, ...) just removes the labels but keeps the axes, unlike axis off. I am generating a group of images with fixed dimensions to combine later into a video. Deleting the axes creates different size frames that can't be recombined.

Related

matlab: plot area continues after data ends

I have a simple plot in Matlab but as you can see from the screenshot. There is a lot of white space on the right side of the graph after the end of the data series.
Any idea how to get rid of this white space and make the plot go right to the edge of the figure? Here is my code:
Plotx = plot(x);
hold on
PlotState = plot(Y);
set(Plotx,'Color','black','LineWidth',2.5);
set(PlotState,'Color','red','LineWidth',2.5);
set(gca, 'XTick',(1:3:62))
labels = time;
set(gca,'XTickLabel',labels(1:3:62))
grid on
This usually works for me:
axis tight;
xlim('auto');
You must select your figure, go back to the console and use those commands so they affect the last active figure.
EDIT: The above line should automatically make your graph axis very tight on your data. For more fine control, you may want to define the axis limits manually:
axis([xmin,xmax,ymin,ymax])
I found a solution. I manually adjust the limit of the x-axis, using:
set(gca,'XLim',[0 63])

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

Remove border around Matlab plot

Matlab is displaying a black border around a plot and I would like to remove it. I think i should be using something like:
set(Figure#,'PropertyName',PropertyValue);
But I'm not sure what PropertyName or PropertyValue should be used...
Edit:
I tried all of the suggestions including:
set(gca,'box','off');
set(gca,'xcolor','w','ycolor','w','xtick',[],'ytick',[]);
axis off;
The figure still has a black boarder and looks like this:
Edit 2:
This is a simplified package that reproduces the black box. Run the script called "runPlot". Here it is:
http://dl.dropbox.com/u/8058705/plotTest.zip
I can't figure out why the box is still visible. This might be due to the line in "plotTEC.m"
axis([-.65 .6 .25 1.32]) % hardwiring axis length since the coastline runs off of the plot
#Pursuit: If I use "plot browser" I get a recursive error....I am not familiar with the matlab plotting package but this seems strange. Does anyone else get this error? Again, thank you guys for your advise!
Does anyone have any other suggestions?
Thanks in advance!
You want to experiment with the properties of the axis. Some properties of interest.
xcolor %The color of the x-axis line and the x axis labels
ycolor %
box %'on', or 'off' indicating if one or both sides of a plot should have lines
xtick %Where to place the labels
ytick
For a completely bare plot, use:
figure
set(gca,'xcolor','w','ycolor','w','xtick',[],'ytick',[])
To set the figure background to white as well
set(gcf,'color','w')
Depending on your exact problem, you can try the 'box' property, to see how it affects your plots
set(gca,'box','on')
set(gca,'box','off')
If you want to turn off the actual plots lines but keep the plot labels then I am not aware of a simple solution. I think that I would need to remove the axes as described above, and then manually add labels using the text function.
Edit: As I just learned from this question, Plot Overlay MATLAB you can also try
axis off
axis on
Which I think is equivalent to
set(gca,'visible','off')
set(gca,'visible','on')
Edit 2:
If nothing else works, activate the "plot browser" in your figure. Use "view" --> "plot browser". From the plot browser panel, uncheck each object until you figure out which object is drawing the lines that you need to remove.
Then double click on the offending object to bring up the "property editor" panel, and mostly likely click "More properties" to view all possible properties of that object. From that view you can (hopefully) figure out what object is drawing the offending lines.
After you have figured out the object and property to edit, you can probably figure out where in the code that object is created, and set the property programmatically.
Try:
set(gca, 'Box', 'off');
Solution to remove 'gray' background in imagesc
I = imread('imgname.jpg');
[rows columns] = size(I);
posX = 100; posY = 100; %you can set any value for posX and posY - try to keep it on screen
f = figure (1);
imagesc(I);
set(gcf,'Position',[posX posY columns rows]);
set(gca,'units','pixels');
set(gca,'units','normalized','position',[0 0 1 1]);
axis off;
axis tight;
This should save the image with same size as that of the original, using imagesc.
Cheers!
set( gca , 'Visible' , 'off' );

Problem or bug in xticklabel_rotate while drawing heatmap and rotating xtick labels in Matlab

I have been drawing heatmaps with labels in Matlab, mainly using the functions imagesc to draw the heatmap and xticklabel_rotate to rotate the xtick labels.
(please see here for xticklabel_rotate).
It usually works well. But today I met some problem which appeared to be caused by xticklabel_rotate (or maybe the Matlab text handle used by xticklabel_rotate?)
To illustrate the problem, in the following I print my code and the results generated from the code (basically, what it does is to randomly generate a normally distributed data matrix, draw a heatmap for the data using imagesc, draw its labels on top and right of the axis, and then rotate xticklabels):
function debug_xticklabelRotate(numX, numY, axisFontsize)
data = randn(numY, numX);
imagesc(data);
colormap(jet);
box on
set(gca, 'ticklength', [0,0]);
set(gca, 'xminortick', 'off', 'yminortick', 'off');
set(gca, 'XAxisLocation', 'top');
set(gca, 'YAxisLocation', 'right');
set(gca,'FontSize', axisFontsize);
axis image
set(gca, 'Xtick', 1 : numX);
htext = xticklabel_rotate([],90, [], 'fontsize', axisFontsize);
set(gca, 'YTick', 1 : numY);
end
Problem 1: I called the above function with parameters as
debug_xticklabelRotate(40, 100, .5);
the output image is shown below (to save space here, I cut the image and only show the top few rows):
Please notice that the bug is that, as the result of calling xticklabel_rotate, neither the right side of the figure box nor the yticklabels are drawn.
Problem 2: When I call the above function with parameters as
debug_xticklabelRotate(40, 200, .5); % only numY is changed from 100 to 200
the output image is shown below (again to save space here, I cut the image and only show the top few rows):
http://i55.tinypic.com/317grdd.png
Compared to the call with numY=100, in this figure both the data image and the labels are shown. However, please notice two problems here. First, the fontsize of xticklabel is not the same as that of yticklabel (axisFontsize). Second, the xtick labels are not aligned well with the columns (xticks): some labels are closer and some are further away.
Please note if I remove the function call of xticklable_rotate in my function debug_xticklabelRotate, all these mentioned problems are gone (except that now the xticklabel are not rotated).
I wish my problem is stated clear above. Any suggestion on solving the problem will be highly appreciated. Thank you very much.
As the author of xticklabel_rotate, I have tried to reproduce the errors mentioned with only small success. I have found an issue with the axis position being changed when y-labels are on the right, which I will look into. I do not get such marked misalignements as you have shown when I run the same examples, so I am not sure how to respond. Please verify that these issues exist when you PRINT the figure, and it is not a simple display issue.
The text boxes are created at the tick positions, in data units. They are middle aligned, there is not much more that can be done, but I am open to suggestions.
PS. I agree it would be nice if this function was inherent in MatLab. If it was, I wouldn't have had to work on this.
If you comment out the line:
set(gca, 'YAxisLocation', 'right')
then it should work as expected. It seems that the XTICKLABEL_ROTATE function does not support right y-labels. You should contact the original author and let him know of the possible bug...

How to create a new figure in MATLAB?

Usually when I plot in MATLAB, it always draws on the same figure. How do I make it draw in a new figure?
I know it is pretty elementary, but I'm not finding it using Google Search.
figure;
plot(something);
or
figure(2);
plot(something);
...
figure(3);
plot(something else);
...
etc.
While doing "figure(1), figure(2),..." will solve the problem in most cases, it will not solve them in all cases. Suppose you have a bunch of MATLAB figures on your desktop and how many you have open varies from time to time before you run your code. Using the answers provided, you will overwrite these figures, which you may not want. The easy workaround is to just use the command "figure" before you plot.
Example: you have five figures on your desktop from a previous script you ran and you use
figure(1);
plot(...)
figure(2);
plot(...)
You just plotted over the figures on your desktop. However the code
figure;
plot(...)
figure;
plot(...)
just created figures 6 and 7 with your desired plots and left your previous plots 1-5 alone.
The other thing to be careful about, is to use the clf (clear figure) command when you are starting a fresh plot. Otherwise you may be plotting on a pre-existing figure (not possible with the figure command by itself, but if you do figure(2) there may already be a figure #2), with more than one axis, or an axis that is placed kinda funny. Use clf to ensure that you're starting from scratch:
figure(N);
clf;
plot(something);
...
As has already been said: figure will create a new figure for your next plots. While calling figure you can also configure it. Example:
figHandle = figure('Name', 'Name of Figure', 'OuterPosition',[1, 1, scrsz(3), scrsz(4)]);
The example sets the name for the window and the outer size of it in relation to the used screen.
Here figHandle is the handle to the resulting figure and can be used later to change appearance and content. Examples:
Dot notation:
figHandle.PaperOrientation = 'portrait';
figHandle.PaperUnits = 'centimeters';
Old Style:
set(figHandle, 'PaperOrientation', 'portrait', 'PaperUnits', 'centimeters');
Using the handle with dot notation or set, options for printing are configured here.
By keeping the handles for the figures with distinc names you can interact with multiple active figures. To set a existing figure as your active, call figure(figHandle). New plots will go there now.
Another common option is when you do want multiple plots in a single window
f = figure;
hold on
plot(x1,y1)
plot(x2,y2)
...
plots multiple data sets on the same (new) figure.
As simple as this-
figure, plot(yourfigure);