Matlab Plot Legend Location Outside

Use the legend object.
Matlab plot legend location outside. You can return the legend object as an output argument from the legend function such as lgd legend then use lgd with dot notation to set properties such as lgd fontsize 14. Sometimes it is necessary or desirable to place the legend outside the plot. Import matplotlib pylab as plt fig ax plt subplots 1 1 figsize 10 6 make the figure with the size 10 x 6 inches fig suptitle example of a legend being placed outside of plot the data x 1 2 3 y1 1 2 4 y2 2 4 8 y3 3 5 14 labels to. Lefthand edge coordinate bottom edge coordinate width height.
Use name value pairs in the legend command. In my case i had many figures with a variable legend size for each figure. Use the legend object. Inside axes where least conflict with data in plot bestoutside outside top right corner of the axes when the legend has a vertical orientation or below the axes when the legend has a horizontal orientation.
For the labels the legend uses the text from the displayname properties of the data series. Then matlab passes the legend. Plot legend below the plot. The location property applies to colorbars and legends but not to axes.
Use name value pairs in the legend command. If the displayname property is empty then the legend uses a label of the form datan the legend automatically updates when you add or delete data series from the axes. My goal was to keep the plot size constant in each figure and just changing the legend size in particular the width through the number of columns. In most cases when you use name value pairs you must specify the labels in a cell array such as legend label1 label2 fontsize 14.
From experimentation though it seems that the four element location vector has the format. The location string can be all lower case and can be abbreviated by sentinel letter e g n ne neo etc. Location with respect to the axes specified as one of the location values listed in this table. Learn more about plotting matlab.
The following code shows how to do it. This much at least is specified in doc legend however the crucial missing information is the units that these four numbers are measured in and through experimentation i have. Using one of the outside values for location assure that the colorbar will not overlap the plot whereas overlaps can occur when you specify any of the other cardinal values. Hi i got a similar problem when i had to put a legend with variable size outside the plot.