Stretching Legend Box between two axes

7 views (last 30 days)
Sasan Rafii-Tabrizi
Sasan Rafii-Tabrizi on 13 Nov 2018
Answered: Prakhar Jain on 16 Nov 2018
Hello,
in the appendix I have a figure with two subplots. It would be nice if the legend box would reach from the left Y-axis to the right Y-Axis. Has anyone got an idea? The code I used to format the legend so far is the following one:
leg1 = legend('\boldmath{$\dot{Q}_{sh,t}$}','\boldmath{$\dot{P}_{t}$}','\boldmath{$\dot{Q}_{S,t}$}','\boldmath{$\dot{Q}_{L,t}$}','\boldmath{$\dot{Q}_{IST\rightarrow DSHP,t}$}','\boldmath{$\dot{Q}_{TS\rightarrow DSHP,t}$}'...
,'\boldmath{$\dot{Q}_{TS\rightarrow IST,t}$}','\boldmath{$T_{TES,t,1}$}','\boldmath{$T_{HC,t}$}','\boldmath{$T_{IST,t}$}','\boldmath{$T_{TS,out,t}$}');
set(leg1,'Interpreter','latex');
set(leg1,'FontSize',10);
legend('Location','northoutside','Orientation','horizontal');
Regards,
SR89

Answers (1)

Prakhar Jain
Prakhar Jain on 16 Nov 2018
Hi Sasan,
Custom location and size, specified as a four-element vector of the form [left bottom width height]. The first two values, left and bottom, specify the distance from the lower left corner of the figure to the lower left corner of the legend. The last two values, width andheight, specify the legend dimensions. The Units property determines the position units.
If you specify the Position property, then MATLAB® automatically changes the Location property to 'none'.
example: legend({'A','B'},'Position',[0.2 0.6 0.1 0.2]);
You can change the width to more to make it appear to full length as shown in figure attached by you.
Follow this link for more legend properties.
Hope this helps.
Thanks.

Tags

Community Treasure Hunt

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

Start Hunting!