Matlab function surf axes going from high to low I want low to high? - matlab

Last question on this I swear.
Right now the plot of surf has the dates going from newest (i.e today) at the left hand side to oldest on the right hand side. I would like it to be the other wat round but keep everything else the same.
Is there a quick way to do this? Without having to reorganise the input data?

You can simply revert the direction of the axis. If it's the x-axis, you write
set(gca,'XDir','reverse')
gca grabs the handle to the currently active axes, so make sure that the surface is on the active figure, or store the axis handle somewhere and pass it instead as first argument to set.
Just replace the X in XDir if you want to do it for a different axis.

This can be set using axis properties:
Direction of increasing values. A mode controlling the direction of increasing axis values. Axes form a right-hand coordinate system. By default:
x-axis values increase from left to right. To reverse the direction of increasing x values, set this property to reverse.
set(gca,'XDir','reverse')
y-axis values increase from bottom to top (2-D view) or front to back (3-D view). To reverse the direction of increasing y values, set this property to reverse.
set(gca,'YDir','reverse')
z-axis values increase pointing out of the screen (2-D view) or from bottom to top (3-D view). To reverse the direction of increasing z values, set this property to reverse.
set(gca,'ZDir','reverse')

Related

MATLAB flip definition of angles (or alternative angular metric)

I am doing work on symmetric images where I would like to define a symmetric (polar) coordinate space. Basically for the left image, I want 0 degrees to be defined along the right horizontal axis (as is the default). However, for the right image, I want 0 degrees to be defined along the left horizontal axis.
I know a phase shift of pi would do the trick. However, for comparison purposes, I am trying to keep the range of angles the same, [-pi : pi).
In the above color plot of the rotations in an object, note that they are both defined in the same direction. Ideally I'd like to see the colors of the right object flipped across its vertical axis.
I should note that these angles are calculated by taking the arctan(y/x) of the perimeter coordinates when measured from the centroid. Is there a different trig function that may result in the proper symmetry? I couldn't seem to come up with one while still claiming it was representative of direction.

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.

Place MATLAB legend such that it does not overlap on the plot

I am generating multiple plots of different datasets in succession using MATLAB. I would like the legend positions to be such that they don't overlap on the plotted lines and it would be ideal if this placement could be done automatically.
I am aware of setting the 'Location' to 'best' to achieve this but the placement of the legend tends to be awkward when 'best' is used (below). Also, I would like the legend to be inside the plot. I also came across a way to make the legend transparent (here) so that it does not render the plotted data invisible, but explicitly placing the legend elsewhere is what I am looking for.
Is there a way to place the legend at the extremes of the image ('NorthWest', 'SouthWest' etc) automatically such that it does not overlap on the plotted data (apart from the methods suggested above)?
So, you have tried using Location instead of Position? For example:
x =1:100;
y = x.^2;
lgd = legend('y = x.^2');
set(lgd,'Location','best')
and you are getting odd results correct? A quick way of solving this would be to still use Location, with best, and extract the coordinates:
lgd.Position
You should get something like this:
ans =
0.7734 0.3037 0.1082 0.0200
which maps to:
[left bottom width height]
You will need to focus on left and bottom. These two values, left and bottom, specify the distance from the lower left corner of the figure to the lower left corner of the legend, and they are analogous to the grid frame you are using.
Then, depending on the size of the frame (I would suggest you use axis([XMIN XMAX YMIN YMAX]) for this, if possible), you can pinpoint the position of the legend within the grid. What you can do next, is check if and which of your graphs in the plot cross paths with the legend (maybe define a relative distance function based on some distance threshold) and if they do, then randomly reposition the legend (i.e. change the values of left and bottom) and repeat until your conditions are met.
If this still troubles you I can write a short snippet. Finally, know that you can always opt for placing the legend on the outside:
set(lgd,'Location','BestOutside')

Core Plot Y axis expandRangeByFactor depends on data?

i have this problem with gap between Y axis changed when different data is being enter.
First: the third data point is close with other points
Second: the third data point is slightly further
Third: the third data point is even further from the other points
Somehow i change expandRangeByFactor then different kind of gap will appear between each Y axis line.
I wonder how can i have the Y axis gap being fix(not affected by the data that i've put in)?
Thanks
Don't change the yRange of the plot space. Be aware that methods like -scaleToFitPlots: and user interaction (scrolling, zooming) can change the ranges, too.

Core Plot :Move only Data

I have created a scatter graph with three plot spaces. One for two y-axis each and one for the x-axis. I am able to show data for both y-axis. However now i want to move only the data,i.e. two line and not the two y-axis.Only the data and x-axis should move.
I have tried allowUserinteraction property. However is I enable it for x-axis, x axis moves without the data. If i enable it for both/either of axis, y axis also moves with data and scale of y-axis is not visible all the time. Can someone help pleas.e This is my first work with core plot.
I will add code if required.
Thanks
Since each plot space has both x and y ranges, I would just use two plot spaces for this situation. Use the same xRange for both plot spaces and assign the x-axis to one of them.
The easiest way to make them scroll only in the X direction is to set the globalYRange to the same range as the yRange for both plot spaces. Set allowsUserInteraction to YES for both plot spaces. If you need to change the yRange later, set the globalYRange to nil before you change the yRange and reset it afterwards. If you ever update the X range manually, be sure to always set it on both plot spaces.