Problem related to legend

6 ビュー (過去 30 日間)
Aftab Ahmed Khan
Aftab Ahmed Khan 2014 年 8 月 28 日
コメント済み: Aftab Ahmed Khan 2014 年 8 月 28 日
Hi everyone, I have made network architecture. I am having a problem with the legends as all of them are straight lines. The black square are buildings. The red-triangles are ABSs. Black stars are User outdoor. Blue circles are user indoor.
Thank you
  2 件のコメント
Star Strider
Star Strider 2014 年 8 月 28 日
We would need to see the code you used to create that plot to figure out what the problem might be.
Aftab Ahmed Khan
Aftab Ahmed Khan 2014 年 8 月 28 日
Hello, kindly look into the attachment.

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

採用された回答

Robert Cumming
Robert Cumming 2014 年 8 月 28 日
When you create your plot save the handles of the plots that you want to add to the legend - then when you create your legend pass the handles to the legend function, see the example below:
hold on;
% create your first plot - give it a name and SAVE the handle to the plot
hh(1) = plot ( [0 10 10 0 0], [0 0 10 10 0], 'k-', 'DisplayName', 'Buildings' );
% plot other stuff - which will have no legend
plot ( [0 10 10 0 0], [30 30 40 40 30], 'k-' )
plot ( [30 40 40 30 30], [0 0 10 10 0], 'k-' )
plot ( [30 40 40 30 30], [30 30 40 40 30], 'k-' )
% next item you want to add to the legend save the handle
hh(2) = plot ( [0:1:40], ones(41,1)+15, 'r-x', 'DisplayName', 'Other' );
% create your legend!
legend ( hh )

その他の回答 (2 件)

Michael Haderlein
Michael Haderlein 2014 年 8 月 28 日
Several possibilities:
- Make the buildings as one object. Put NaN values between the xy values of the buildings to separate them from each other.
- First plot users and the ABSs, then the buildings.
- Plot 4 dummys (just nan values) and give them the corresponding displaynames and markers/linestyles/colors. Then plot what is shown in your figure.

Andrew Reibold
Andrew Reibold 2014 年 8 月 28 日
編集済み: Andrew Reibold 2014 年 8 月 28 日
I looked at your code and know exactly why your legend is doing this.
Early on in your code, you used this command four times before anything
plot(bx11,by11,'-k')
These are your four buildings, and you made them with black lines. When you use the legend command, it automatically generates the color and style in the same order that you plotted in . This means your first for legend entries you make will be these black lines.
There are different ways to solve this problem. I recommend saving handles of the plots you have. Robert has shown you how to do this, I'm just identifying what the problem was.
If possible, it might be easier just to plot your data first and the buildings and red triangles afterwards... this will give priority to your real data to be made in the legend first! :)
  7 件のコメント
Aftab Ahmed Khan
Aftab Ahmed Khan 2014 年 8 月 28 日
Why it is showing me "getcolumn" thing in the third line ?
Aftab Ahmed Khan
Aftab Ahmed Khan 2014 年 8 月 28 日
Hi, thank you Robert. I done it.

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

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by