how to always display "labels" on axis X - matlab

If I zoom several time graph all labels from axis X disapear (go away) and there are no visible axis X labels so it is not possible to understand the part of graph where am I.
How can I force matlab to always display labels on axis X and to update them automatically while zooming and to display enough digits so "neighboor" labels must be different.

it depends, are you manually setting the tick marks yourself ('XTick' and 'XTickLabel' axis properties)?
Try this simple example
plot(sin(1:10), 'o-')
without changing anything, you can zoom as much as you want, and the tick labels will always be visible
EDIT
The root cause of the problem is the same as the one raised in your other question, datetick function will manually set the tick labels, thus disabling automatic update on zoom/pan.
The good news is there are already submissions on FEX that tries to solve this exact problem with DATETICK

I run into the same problem even on the new version of MATLAB (r2014). MATLAB does not display sufficient x-axis tick labels as you zoom-in. After several experiments I found the following workaround. Following is a plot before implementing the solution. MATLAB displays only three XTick labels on the x-axis even though there is sufficient space for more (there are often even less labels as you zoom in more).
Suspecting that MATLAB thinks that it does not have sufficient space to display more labels, a workaround can be to rotate the labels. To do that, after you issue the plot commands, e.g.
plot(tsX);
hold on;
plot(tsY);
plot(tsZ);
add the following command
set(gca,'XTickLabelRotation',90);
Now MATLAB plots with more labels
I am going to report this as a bug to the MATLAB guys.

Related

Why is my axis position data changing when I use copyobj in MATLAB?

I'm creating a plot in Matlab with two axes, and I want to copy the entire figure to a smaller window with a specific size, and then save it (this makes it easier to format plots for display in Word documents). The function I'm using is as follows:
function printStandardFigure(figInput,filename)
dpi = 300;
newFig = copyobj(figInput,groot);
newFig.Units = 'inches';
newFig.InnerPosition = [1,1,6.5/2,6.5/2];
print(filename,'-dpng',['-r',num2str(dpi)]);
close(newFig);
end
In theory, this should create a copy of the figure I've made with all its axes, etc. identical to the original but resized to fit the new window size. What actually happens is that the 'Position' property for one of the axes gets reset to [0, 0, 1, 1], but the other one displays just fine. This still happens even when I set the ActivePositionProperty to 'position', which normally causes the axis to hold the Position property constant.
I've also tried using copyobj to copy just the two axes over to the new figure, but I have similar issues with resizing, and this doesn't import any legends even though they are set as children of the axes.
This code works just fine if I only have one axis, so why does the second axis cause it to screw up? I've tried making the original figure have the same aspect ratio as the new one, and I've tried setting their sizes to be exactly equal using the InnerPosition property. I can't figure out what's going on and Matlab's documentation isn't helping.
Here's the original chart
And here's what the output of my function looks like.
Edit: Cris Luengo in the comments suggested I try the subplot command, which I thought was a good idea, so I tried it out. However, the export process is still causing a problem Here are the original and the exported versions of the plot when I do that. The original figure was created to have the same dimensions as the exported plot, just to make sure that resizing the axes wasn't causing the issue. I also get the same problem when I remove lines 6 and 7 from the export function (where I set the size of the new figure).

How to reverse the direction of Y-Axis of MatLab figure generated by `imagesc()` function

I am trying to display data in a matrix using imagesc() function but it is showing row index in decreasing order (Assuming origin at left-bottom). Any idea what mistake i could be making or how to correct this?
The matrix only has zeros and ones in it.
Set Ydir property of the current axes to normal
By default, imagesc uses reverse for YDir
set(gca,'YDir','normal');
See Documentation for Axes properties
Before:
After:
Note: This completely flips the inside data as well (it supposed to). As you are dealing with matrices, I hope this is what you want.
If you don't want to affect inside data, you need to change order of YTickLabels instead.
There's another option which requires slightly less code:
axis ij
Reverse the coordinate system so that the y values increase from top to bottom.
As in this case (as it is already reversed), you could use
axis xy
To get back to normal, so that y values increases from bottom to top.
As mentioned in the docs of axis.

MATLAB: Plotting two different axes on one figure

The MATLAB surf plot below is essentially two plots plotted adjacent to each other. For clarity, I have included some code below used to prepare the plot:
band1 = horzcat(band1, eSurface2(:,:,1));
band2 = horzcat(band2, eSurface2(:,:,2));
surf(band2,'DisplayName','band2');
surf(band3,'DisplayName','band2');
I would like for the y axis numbering to restart at the start of the second graph. How do I go about doing that?
You can use the 'YTick' and 'YTickLabel' properties of the axis to control the ticks, this way you can make it start from zero for the second graph. It will require some trail and error to get it right. See the relevant doc here (you'll have to scroll all the way to the bottom of the page).
Take advantage of the following feature of 'YTickLabel': "If you do not specify enough text labels for all the tick marks, MATLAB uses all of the labels specified, then reuses the specified labels".

how to add additional label on x-axis on the rightmost in matlab figure?

I have the tick label set for the x-axis already and I also have the label set for the x-axis too. I am seeking a way to put an additional x label to the rightmost of the figure next to the x tick labels, is there any way to do so? Thanks
just like the following figure, the x ticks was added automatically and x label was added by the command xlabel. But I want to add one additional label "add'l" (red) in the figure. But I have many plots and/or subplots and the axes might be different, so I need to add that label with problem instead of manually.
I suggest using a uicontrol that will be carefully placed in the relevant area.
uicontrol('style','text',....);
If your UI is resizable, be sure to have the same units, i.e. if the text units are Normalized, then the axes units should be Normalized as well.
Check out this example on the MATPLOTLIB gallery page: http://matplotlib.org/examples/pylab_examples/alignment_test.html
It shows adding all kinds of different text to the axis.

How to change the format of the numbers displayed on an axis in a MATLAB plot?

I actually have 3 questions:
I have a plot with data that is in the thousands and my plot's axis is diplaying the tick marks as .4 .8 1.0 1.2 and a *10^4 in the lower right. This is a little annoying.
Besides dividing my data by 1000 or hardcodig the tick marks is there a way to change to tick marks from .4*10^4 TO 4000?
Seems like this should be trivial but aftter browsing through all of the figure's properties I can't seem to get an where.
And...once I get 4000 to apear instead of .4*10^4 is there a way to rotate the tick mark label so it is not overlapping the other labels.
And..how do you set how many "major" tick marks there are?
Thanks so much!
ME
Try the following:
x=[4000, 8000, 10000, 12000]; % define the x values where you want to have a tick
set(gca,'XTick',x); % Apply the ticks to the current axes
set(gca,'XTickLabel', arrayfun(#(v) sprintf('%d',v), x, 'UniformOutput', false) ); % Define the tick labels based on the user-defined format
Reference: Mathworks
In regards to the label rotation, it seems that Matlab does not support such feature by its own, but someone wrote a script for the label rotation, and you might want to give it a try.
There's a nice function by Yair Altman called ticklabelformat to do that in case you want to still be able to freely play with the axes afterwards
description:
http://undocumentedmatlab.com/blog/setting-axes-tick-labels-format/
and the download link:
http://www.mathworks.com/matlabcentral/fileexchange/36254-ticklabelformat-set-a-dynamic-format-of-axes-tick-labels