Data not aligned after zooming into figure using plotyy

조회 수: 3 (최근 30일)
Ivan Teng
Ivan Teng 2024년 3월 14일
댓글: Voss 2024년 3월 18일
Hi!
Using Matlab 2023b.
Plotting some data using plotyy, here is the example code:
data1 = [1 2 3 2.5 5 6 7];
data2 = [10 20 30 25 50 60 70];
Timestamp_datetime1 = datetime(2014,1:7,1)
Timestamp_datetime2 = datetime(2014,2:8,1)
figure
[hAx,hLine1,hLine2] = plotyy(Timestamp_datetime1, data1,Timestamp_datetime2, data2,'scatter','plot')
hLine2.LineStyle = '--'
Run the code and you will get this:
If I use the zoom in function and select the data around Apr 2014, I get this:
The data points are now out of alignment on the graph.
Has anybody come across this?

채택된 답변

Adam Danz
Adam Danz 2024년 3월 15일
편집: Adam Danz 2024년 3월 18일
plotyy is not recommended. Instead, use yyaxis which replaces plotyy. I've converted your code below. yyaxis does not have the problem you've found in plotyy.
data1 = [1 2 3 2.5 5 6 7];
data2 = [10 20 30 25 50 60 70];
Timestamp_datetime1 = datetime(2014,1:7,1);
Timestamp_datetime2 = datetime(2014,2:8,1);
figure
yyaxis left
hLine1 = plot(Timestamp_datetime1, data1,'o');
yyaxis right
hLine2 = plot(Timestamp_datetime2, data2,'--');
  댓글 수: 4
Ivan Teng
Ivan Teng 2024년 3월 18일
Sorry, I missed that
Thank you!
Voss
Voss 2024년 3월 18일
No worries, and you're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by