Problem related to legend
显示 更早的评论
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
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
2014-8-28
采纳的回答
更多回答(2 个)
Michael Haderlein
2014-8-28
0 个投票
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
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
2014-8-28
Robert Cumming
2014-8-28
handle is a matlab function (see which handle) - try another variable...
Aftab Ahmed Khan
2014-8-28
Robert Cumming
2014-8-28
You could save your third plot handle as a temp var and use one of those to pass to the legend.
multipleHandles = plot ( ..... );
hh(N) = multipleHandles(1);
My solution shows you what you need to do - just update your code to fit that methodology.
Aftab Ahmed Khan
2014-8-28
Aftab Ahmed Khan
2014-8-28
Aftab Ahmed Khan
2014-8-28
类别
在 帮助中心 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
