How to get consistent subplot widths with legend outside?
78 次查看(过去 30 天)
显示 更早的评论
I want to put my legends outside the plot so they never cover any data, but also want the subplots to have the same width since they'll all have the same X data. If the legends have variable width, the auto-positioning makes the sub plots different widths. Is there anyway to get around this?
0 个评论
采纳的回答
Kevin Phung
2019-2-18
You can assign a handle to the legends and set all their xpositions to be the same. Do the same for the subplots.
ex:
%some_x_position = whatever you want
%some_length = whatever you want
s1 = subplot(3,1,1)
plot(x1,y1)
l1 = legend
l1.Position(1) = some_x_position % position is an array of [x y l h ]
s1.Position(3) = some_length
s2 = subplot(3,1,2)
plot(x2,y2)
l2=legend
s2.Position(3) = s1.Position(3)
l2.Position(1) = l1.Position(1)
s3 = subplot(3,1,3)
plot(x3,y3)
l3=legend
s3.Position(3) = s1.Position(3)
l3.Position(1) = l1.Position(1)
note: you can call out the handles to see if their position is 'normalized' (w.r.t. figure) or 'pixels'. and set your x position / lengths accordingly.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!