Changing the scale of axis in surf plot

Hello,
I plotted a 3D graph using 'surf' function. I want to change the axis scale to different values. My X-axis is 0:10:70. I want to convert X-axis to a scale having 0 at center of the axis and -35 and +35 on the both sides. Is it possible to do that?
Thanks in advance.

 Accepted Answer

Adam Danz
Adam Danz on 30 Apr 2019
Edited: Adam Danz on 30 Apr 2019
How to change the limits and ticks on the x axis
h = surf(X,Y,Z); % save handle to surface object
axHand = h.Parent; % alternative: gca()
axHand.XTick = -35 : 5 : 35;
axHand.XLim = [-35, 35];
How to shift your data down the x axis
shift = -35; %shift 35 units leftward (neg) or rightward (pos)
h = surf(X+shift, Y, Z);

9 Comments

I am getting the plot starting from 0 till 70. And when I use the above mentioned code, in result I am getting plot data just from 0 till 35. In the region -35 to 0 it is completely empty. In short plot has been trimmed.
I want to change the scale without losing any point on the plot.
I originally interpretted your question as changing the limits (and ticks) of the x axis (not changing your data). Now it seems you either want to laterally shift your data down the x axis and/or rescale your data to a different range along the x axis. Those are two very different interpretations so please let me know exactly what you'd like to do so I can guide you in the right direction.
An image might help.
I want to rescale my data. On X-axis data is from 0 to 64 scale. Keeping the plot same I just want to change the axis [-32 32]. The biggest peak in the picture is approx.at 0. From there, on the left I want negative scale and on right positive scale.
I see. That's not technically a 'rescale'. What you're describing is a shift of your data. I'll provide a new answer in a few moments.
I updated my answer above with a second section that addresses the lateral shift of your data down the x axis. Please let me know if there are further questions or corrections to my interpretation.
That worked. Thank you so much for your replies.
Hi
I have similar problem. How can I make a surf plot with y axis having two diffrent scale. for y from -10 to 10 , I need linear scale and from10 to 3000, I need log scale.
Hi Bibek, that's not really similar to this problem. It's not possible to assign two axis scales to a single axis. You can kludge it in by changing the tick marks, though. I suggest asking a new question.

Sign in to comment.

More Answers (1)

If you know the specific limits of your axis, may you use the x,y - ticklabels funtion. It works perfectly
Example:
xticklabels({80 85 90 95 100})
yticklabels({20 25 30 35 40})

2 Comments

I wouldn't recommend this approach because the real x and y values for your data are no longer represented in the plot. This makes troubleshooting difficult and it can be misleading to viewers who aren't familiar with the code or your future-self who has forgotten that he tick labels have been changed.
It's much better to change the actual x and y values in your data so that the axis ticks represent the actual data values.
I agree, however when you work with codificated variables the response surface change acording to tbis data. Its more understadable plot with real variables although the plot was with the codificated.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!