I am trying to do a scatter plot with 2 different Y axes with different scales using imported data on a graph.
조회 수: 7 (최근 30일)
이전 댓글 표시
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
답변 (2개)
KSSV
2022년 12월 22일
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
Bora Eryilmaz
2022년 12월 22일
편집: Bora Eryilmaz
2022년 12월 22일
% Dataset in a table
T = table((1:100)', cumsum(rand(100,1)), cumsum(rand(100,1)), 'VariableNames', {'Time', 'Data1', 'Data2'})
% 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
Benjamin Kraus
2022년 12월 23일
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')
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!