Data not aligned after zooming into figure using plotyy
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1642751/image.png)
If I use the zoom in function and select the data around Apr 2014, I get this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1642756/image.png)
The data points are now out of alignment on the graph.
Has anybody come across this?
0 commentaires
Réponse acceptée
Adam Danz
le 15 Mar 2024
Modifié(e) : Adam Danz
le 18 Mar 2024
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Two y-axis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!