Label a plot as contour function does

6 ビュー (過去 30 日間)
Filippo Manoli
Filippo Manoli 2022 年 11 月 11 日
コメント済み: Voss 2022 年 11 月 11 日
I want to label a plot using a label located on the drawed line, just as the countour function does.
I found that I can transform my function plot to a matrix (source) that I can give as input to the contour function
cols = 1:500 ;
rows = 150 + 100*sin(cols/100) ;
M = zeros(300,500) ;
idx = sub2ind(size(M), floor(rows), cols) ;
M(idx) = 1 ;
contour(M,'LevelList',1,'ShowText','on') ;
This produce the following figure
But this plot is not visible in all the domain, has two labels (I would like just one) and the label has not a white background (the number 1 intersect the line). How can I obtain a label like the following?

採用された回答

Voss
Voss 2022 年 11 月 11 日
Sounds like you want to use text:
x = 1:500 ;
y = 150 + 100*sin(x/100) ;
plot(x,y)
text(50*pi,250,'1', ...
'BackgroundColor','w', ...
'HorizontalAlignment','center')
ylim([0 300])
  2 件のコメント
Filippo Manoli
Filippo Manoli 2022 年 11 月 11 日
Thank you, that's exactly what I needed! :)
Voss
Voss 2022 年 11 月 11 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by