How to do different scaling in x in maltab plot (multiple scales in X axis)?

4 visualizaciones (últimos 30 días)
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 :(

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 29 de Oct. de 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

Más respuestas (1)

Mathieu NOE
Mathieu NOE el 29 de Oct. de 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 comentarios
sun
sun el 3 de Nov. de 2020
Editada: sun el 3 de Nov. de 2020
hey, friend. Thanks so much for your code and time! It's awesome.
I do saw your style ~ you played tricks on the side of algorithm, and it's truly working! However, there is only one downside, it's not that simple. Buddy, please check another answer here. I applied his way, it's very simple styple. What you do is, you plot 3 different scale, then put them together on one figure.
Thank you again!
Mathieu NOE
Mathieu NOE el 4 de Nov. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by