how to modify the axes scale when we plot values in both y axis with same x axis line.

x1=xlsread('ERROR.xlsx') y1=xlsread('ROUND.xlsx') plot(x1); xlabel('data ratio'); ylabel('Percentage Error'); yyaxis right;
plot(y1); ylabel('Energy');
ERROR DATA 53.7578 31.3263 6.5007 2.3187 1.0973 0.9278 0.9654 0.7224 0.6327 0.549 0.4588 0.3607 0.3277 0.235 0.0671 0.1379 5.45E-02 7.50E-04 9.65E-07
ROUND DATA 282 299 305 324 341 360 378 394 413 481 496 550 569 728 794 804 1000 1000 1000 OUTPUT
how do i change in x axes,yaxes,yaxes right.In this particular example above I want to change the limit of x axes 0 to 1 with difference .1,y axxes 0 to 100 with difference 10,yaxes right 1000 to 100 with difference -50.

5 comentarios

What do you mean buy you want to scale? Do you want to adjust the limits of the axes in the plot or do you want to scale your error data such that in the scaled version 53.75 corresponds to 100 and 9.65e-7 corresponds to 0?
I only want to adjust the limits of the axes . x axes 0 to 1 with difference .1,y axxes 0 to 100 with differnce 10,yaxes right 1000 to 100 with difference -50.
Those are really dense intervals and you did not supply data for the x-axis. I am sharing the code for more coarse intervals where you can play with the numbers to change however you see fit. the "e" and "o" variables are the error and the output you had in your post. If you want grids as well, you can try "grid on" or "grid minor" after the plot is generated.
e = [53.7578 31.3263 6.5007 2.3187 1.0973 0.9278 0.9654 0.7224 ...
0.6327 0.549 0.4588 0.3607 0.3277 0.235 0.0671 0.1379 5.45E-02 ...
7.50E-04 9.65E-07];
o = [282 299 305 324 341 360 378 394 413 481 496 550 569 728 ...
794 804 1000 1000 1000];
x1 = e; y1 = o;
plot(x1); xlabel('data ratio'); ylabel('Percentage Error');
set(gca,'xLim',[0 20]) % x-axes lim to 0 - 20
set(gca,'yLim',[0 100]) % y-axes lim to 0 - 100
set(gca,'xTick',0:1.3:20)% x-axes ticks 0 to 20 with 1.3
set(gca,'yTick',0:7:100) % y-axes ticks 0 to 100 with 7
yyaxis right;
plot(y1)
set(gca,'yLim',[100 1000]) % y-axes right limits 0 and 1000
set(gca,'yTick',100:50:1000)% y-axes right 100 and 1000 with 50
set(gca,'Ydir','reverse') % flip the y-axis right
This quite ok,with slight problem.X axes range within 0 to 1 with difference .1
For that you need to specify the xData as well. Since you are plotting like "plot(y1)", x-axis represent the data number (data #1, data #2). This is the reason why the first data point is at x = 1, second one is x = 2 and so on.
If you have the xData, you need to plot using "plot(xData,y1)". So that when you set the x-axis to be between 0 and 1, there will be data there assuming xData is between 0 and 1.
To change the x-axis range, make this change in the code;
set(gca,'xLim',[0 1])
set(gca,'xTick',0:.1:1)

Iniciar sesión para comentar.

Respuestas (1)

From my understanding of the question, you want to change the number of ticks and their corresponding labels in the plot. To achieve that, please follow the below steps which considers a random data set for plotting.
y = [282 299 305 324 341 360 378 394 413 481 496 550 569 728 794 804 1000 1000 1000]
plot(y)
xticks([0:2:20])
xticklabels([0:0.1:1])
Follow the same steps for changing the labels for both the y axes.

Categorías

Más información sobre Axes Appearance en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 8 de Jun. de 2018

Comentada:

el 8 de Jun. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by