# I am trying to do a scatter plot with 2 different Y axes with different scales using imported data on a graph.

9 visualizaciones (últimos 30 días)
Yulia Gitter el 22 de Dic. de 2022
Comentada: Yulia Gitter el 24 de Dic. de 2022
I am trying to make a scatter plot of two data sets with the same x axis but two different y axis. I see how to do it with a line plot but can not seem to figure it out with a scatter plot with imported data from a table. Any help would be appreciated. Thank you.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (2)

KSSV el 22 de Dic. de 2022
x1 = rand(1,10) ;
y1 = rand(1,10) ;
z1 = sqrt(x1.^2+y1.^2) ;
yyaxis left
scatter(x1,y1,[],z1,'filled','O')
x2 = x1;
y2 = rand(1,10)+10 ;
z2 = sqrt(x2.^2+y2.^2) ;
yyaxis right
scatter(x2,y2,[],z2,'filled','s')
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Bora Eryilmaz el 22 de Dic. de 2022
Editada: Bora Eryilmaz el 22 de Dic. de 2022
% Dataset in a table
T = table((1:100)', cumsum(rand(100,1)), cumsum(rand(100,1)), 'VariableNames', {'Time', 'Data1', 'Data2'})
T = 100×3 table
Time Data1 Data2 ____ _______ _______ 1 0.48783 0.25794 2 0.52543 1.0037 3 1.1565 1.5112 4 1.7177 1.8596 5 2.4556 1.9385 6 2.8473 2.7949 7 3.1231 3.0652 8 4.0823 3.3043 9 4.7703 3.4385 10 5.5753 4.2247 11 6.3436 4.5791 12 6.7197 5.3782 13 7.0281 6.0013 14 7.7479 6.9337 15 8.3779 7.3871 16 9.2435 7.4251
% Left plot
x = T.Time;
y = T.Data1;
yyaxis left
scatter(x,y)
ylabel('Data 1')
% Right plot
z = T.Data2;
yyaxis right
scatter(x,z)
ylabel('Data 2')
##### 6 comentariosMostrar 4 comentarios más antiguosOcultar 4 comentarios más antiguos
Benjamin Kraus el 23 de Dic. de 2022
Where the data originates is not relevant, if the data is stored in MATLAB table, you can use yyaxis the way @Bora Eryilmaz shows in his post.
The code from your screen shot is calling readtable, which reads a table (in this case from an Excel spreadsheet) and creates a MATLAB table. On the right side of your screenshot you can see you have a MATLAB table with 1568 rows and 7 variables. Your data is in a table, so you can use yyaxis.
For example:
yyaxis left
scatter(dec22LN2testingPROCESSEDS2.DelTmin,dec22LN2testingPROCESSEDS2.OutletK)
yyaxis right
scatter(dec22LN2testingPROCESSEDS2.DelTmin,dec22LN2testingPROCESSEDS2.MassFlow)
Note that starting in R2021b you can use a different syntax for plotting data in a table:
yyaxis left
scatter(dec22LN2testingPROCESSEDS2,'DelTmin','OutletK')
yyaxis right
scatter(dec22LN2testingPROCESSEDS2,'DelTmin','MassFlow')
Yulia Gitter el 24 de Dic. de 2022
Oh thank you so much for all the help! I am still in the process fo learning matlab. I really appreciate it!

Iniciar sesión para comentar.

### Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by