![]() ![]() legend (loc 'lower left', bboxtoanchor (.5 + np. You might also take a look at plt.figlegend(). The following snippet places the legend's lower left corner just outside the polar axes at an angle of 67.5 degrees in polar coordinates. ![]() Have a look at the matplotlib legend guide. # Shrink current axis's height by 10% on the bottomĪx.set_position([box.x0, box.y0 + box.height * 0.1,Īx.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), # Put a legend to the right of the current axisĪx.legend(loc='center left', bbox_to_anchor=(1, 0.5))Īnd in a similar manner, shrink the plot vertically, and put a horizontal legend at the bottom: import matplotlib.pyplot as plt When you save a file, things are not being done automatically, so you need to specify the size of your figure, and then the bounding box of your axes object. Line, = ax.plot(x, i * x, label='$y = %ix$'%i)Īx.legend(loc='upper center', bbox_to_anchor=(0.5, 1.05),Īlternatively, shrink the current plot's width, and put the legend entirely outside the axis of the figure (note: if you use tight_layout(), then leave out ax.set_position(): import matplotlib.pyplot as pltĪx.set_position() The problem is that when you plot dynamically, matplotlib determines the borders automatically to fit all your objects. Similarly, make the legend more horizontal and/or put it at the top of the figure (I'm also turning on rounded corners and a simple drop shadow): import matplotlib.pyplot as plt ![]() If we do the same thing, but use the bbox_to_anchor keyword argument we can shift the legend slightly outside the axes boundaries: import matplotlib.pyplot as plt So, let's start with a generic example: import matplotlib.pyplot as plt To add to what and already said, you can use the bbox_to_anchor keyword argument to place the legend partially outside the axes and/or decrease the font size.īefore you consider decreasing the font size (which can make things awfully hard to read), try playing around with placing the legend in different places: There are a number of ways to do what you want. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |