I have a series of 20 plots (not subplots) to be made in a single figure. I want the legend to be outside of the box. At the same time, I do not want to change the axes, as the size of the figure gets reduced. Kindly help me for the following queries:
- I want to keep the legend box outside the plot area. (I want the legend to be outside at the right side of the plot area).
- Is there anyway that I reduce the font size of the text inside the legend box, so that the size of the legend box will be small.
Just call
legend()
call after theplot()
call like this:Results would look something like this:
Not exactly what you asked for, but I found it's an alternative for the same problem. Make the legend semi-transparant, like so:
Do this with:
Short Answer: Invoke draggable on the legend and interactively move it wherever you want:
Long Answer: If you rather prefer to place the legend interactively/manually rather than programmatically, you can toggle the draggable mode of the legend so that you can drag it to wherever you want. Check the example below:
don't know if you already sorted out your issue...probably yes, but... I simply used the string 'outside' for the location, like in matlab. I imported pylab from matplotlib. see the code as follow:
Click to see the plot
As noted, you could also place the legend in the plot, or slightly off it to the edge as well. Here is an example using the Plotly Python API, made with an IPython Notebook. I'm on the team.
To begin, you'll want to install the necessary packages:
Then, install Plotly:
This creates your graph, and allows you a chance to keep the legend within the plot itself. The default for the legend if it is not set is to place it in the plot, as shown here.
For an alternative placement, you can closely align the edge of the graph and border of the legend, and remove border lines for a closer fit.
You can move and re-style the legend and graph with code, or with the GUI. To shift the legend, you have the following options to position the legend inside the graph by assigning x and y values of <= 1. E.g :
{"x" : 0,"y" : 0}
-- Bottom Left{"x" : 1, "y" : 0}
-- Bottom Right{"x" : 1, "y" : 1}
-- Top Right{"x" : 0, "y" : 1}
-- Top Left{"x" :.5, "y" : 0}
-- Bottom Center{"x": .5, "y" : 1}
-- Top CenterIn this case, we choose the upper right,
legendstyle = {"x" : 1, "y" : 1}
, also described in the documentation:Create font properties