簡體   English   中英

Matlab:情節中的可變圖例

[英]Matlab: variable legend in plot

我有一個圖,其中繪制了可變數量的點(類似於網絡的節點)和三個軌跡。 當我調用legend也會獲得軌跡的o符號(對應於節點)。

我知道這是因為legend函數需要為每個標簽添加一個字符串,但是由於我不知道“先驗”節點的總數(因為它是用戶定義的參數),因此有一種方法可以指定能夠正常地標記軌跡時,僅將節點標記為o

您只需要准確告訴legend您想要什么即可。

軌跡:

t(1) = plot( xvector1, yvector1, linspecs ...)
t(2) = plot( xvector2, yvector2, ...)
...
t(n) = plot( xvectorn, yvectorn, ...)

及其標簽:

tLabel{1} = 'trajectory label #1'
...
tLabel{n} = 'trajectory label #n'

節點相同:

p(1) = plot( x1, y1, 'o',...)
p(2) = plot( x2, y2, 'o',...)
...
p(m) = plot( xm, ym, 'o',...)

pLabel{1} = 'node label #1'
...
pLabel{m} = 'node label #m'

最終繪制了圖例:

lh = legend( [traj(1:n),p(1:m)] , tLabel{1:n}, pLabel{1:m} );

當然,如果所有節點都具有相同的名稱和樣式,則只需使用節點數組的第一個條目:

lh = legend( [traj(1:n),p(1)] , tLabel{1:n}, pLabel{1} );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM