How to add a line to scatter plot
14 ビュー (過去 30 日間)
古いコメントを表示
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','*')

0 件のコメント
採用された回答
その他の回答 (1 件)
Chunru
2021 年 8 月 29 日
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 件のコメント
Cris LaPierre
2021 年 8 月 29 日
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.
参考
カテゴリ
Help Center および File Exchange で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!