How to get a Negative Positive Negative Y axis labels?

68 views (last 30 days)
Hey Guys,
I have 3 column matrix which I would like to plot as a 3d surf plot with each column representing each axis. The values in Y axis increases from -0.4 to 1.4 and the decreases to -0.4 again. Something like
Y= [-0.4 -0.2 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.2 1 0.8 0.6 0.4 0.2 0 -0.2 -0.4];
The problem is when I plot it using surf function, the y axis looks like -0.4 to 1.4. and the data is plotted as such, but I would like to plot the values in y axis to first increase and decrease, similar to the data (so the Y axis must have labels same as the data - Negative Positive Negative). But I am always getting the y axis with just increasing values and the x and z values corresponding to the downward slope (1.4 to -0.4) is just plotted as an inverted surface. Is there a solution for this?
Thanks

Accepted Answer

Star Strider
Star Strider on 3 May 2019
The y-tick values must be increasing. However you can choose the y-tick labels to be (almost) whatever you want.
Try this:
Y= [-0.4 -0.2 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.2 1 0.8 0.6 0.4 0.2 0 -0.2 -0.4];
yt = get(gca, 'YTick'); % Get Y-Tick Values
ytx = linspace(min(yt), max(yt), numel(Y)); % New Y-Tick Values
ytl = sprintfc('%.1f',Y); % New Y-Tick Labels
set(gca, 'YTick',ytx, 'YTickLabel',ytl) % Set New Y-Tick Labels
I cannot test this because I do not have your data. It should work.
  12 Comments
Star Strider
Star Strider on 19 May 2019
My pleasure!
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!