Effacer les filtres
Effacer les filtres

How to add a line to scatter plot

23 vues (au cours des 30 derniers jours)
Nuria Andreu
Nuria Andreu le 29 Août 2021
Commenté : Nuria Andreu le 29 Août 2021
Hello! I created a scatter plot with maximum temperatures and daily data from the 1930s to 2020. I want to create a straight line in the 100F (for high temperature reference) in my y axis but I can't. I tried many codes from Matworks but no success.
Hope anyone can help me with this.
This is the plot I get and the code I used
figure('Name','Daily TMAX');
hold on
scatter(Date,DailyTMAX,'b','*')

Réponse acceptée

Cris LaPierre
Cris LaPierre le 29 Août 2021
Use yline.
scatter(rand(1,100),rand(1,100),'b','*')
yline(0.7)
  1 commentaire
Nuria Andreu
Nuria Andreu le 29 Août 2021
Thank you!! it worked

Connectez-vous pour commenter.

Plus de réponses (1)

Chunru
Chunru le 29 Août 2021
Date = datetime([1930:2020], 1, 1);
DailyTMAX = randn(size(Date));
figure('Name','Daily TMAX');
hold on
scatter(Date,DailyTMAX,'b','*')
yline(max(DailyTMAX), 'r--')
  3 commentaires
Cris LaPierre
Cris LaPierre le 29 Août 2021
Just a comment that hold on is not necessary when using xline or yline. However, adding it has no adverse effect.
Also, it is best practice to always pair a hold on with a corresponding hold off.
Nuria Andreu
Nuria Andreu le 29 Août 2021
Thank you Cris, I will practice more!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by