How to do different scaling in x in maltab plot (multiple scales in X axis)?
    10 views (last 30 days)
  
       Show older comments
    
Dear friends, 
I have a "simple" plot question here, but I cant figure out. In my project, I need to give different scaling in x axis. Because the information in some ranges are not improtant.  I made a simple example to demonstrate my question, hope it's clear enough. 
Please check the pic I attached. Lets assume my "curve" is this Y = X,  X= [0:1:90].  However, the Y information for given X = [A:1:B ] is not improtant, so I just want to SHRINK or make it smaller, so that other range X=[0:A] & [B:90] information will be enlarged and easier to read.  
Lets say A=30, B =60, C = 90.  (Actually, any number is fine, just trying to make an simple example.)   Anyone can advise me how to do it ?  thanks in advance.
I tried to do [A:10:B] , but after the plot, the position of A B dont change, so not working :( 

0 Comments
Accepted Answer
  Ameer Hamza
      
      
 on 29 Oct 2020
        There is no built-in command to do such a thing in MATLAB. One of the workarounds is to create multiple axes objects and connect them seamlessly. Refer to my answer here: https://www.mathworks.com/matlabcentral/answers/601147-extending-specific-y-axis-values
More Answers (1)
  Mathieu NOE
      
 on 29 Oct 2020
        hello
forget my first attempt (deleted)
here hopefully a better code.
% let's generate some data
X= [0:1:90];
Y = 2*X;
% A, B segment indexes 
indA = (1:31);  % take the first 30 values
indB = (61:91);  % take the last values
ind_shr = (max(indA):10:min(indB)); % shrinked portion of data
XA = X(indA);
YA = Y(indA);
XB = X(indB);
YB = Y(indB);
X_shr = X(ind_shr);
Y_shr = Y(ind_shr);
% plot vectors / indexes
X_shr_plot = X_shr(1)+(0:length(X_shr)-1);
XB_plot = X_shr_plot(end)+(0:length(XB)-1);
figure(1)
plot(XA,YA,'b',X_shr_plot,Y_shr,'--b',XB_plot,YB,'b');grid
x_vector_ticks = [XA X_shr(2:end-1) XB];  % remove for Xtick labels the first and last element of X_shr (they already appear in XA(end) and XB(1)
for ci = 1:length(x_vector_ticks)
    XtickLabel{ci}  = num2str(x_vector_ticks(ci));
end
xticks(0:length(x_vector_ticks)-1)
xticklabels(XtickLabel)
xlabel('X value')
ylabel('Y value')
2 Comments
  Mathieu NOE
      
 on 4 Nov 2020
				hello
yes, I recognize it's a bit trickky - but the other option does not work on my older matlab. 
I'm used to do complicated stuff that is easier now with newer matlab
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

