How to put the legend out of the plot

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:

  1. 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).
  2. 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.

Answer

You can make the legend text smaller by creating font properties:

from matplotlib.font_manager import FontProperties

fontP = FontProperties()

fontP.set_size('small')

legend([plot1], "title", prop=fontP)

# or add prop=fontP to whatever legend() call you already have

以上是 How to put the legend out of the plot 的全部内容, 来源链接: www.h5w3.com/37787.html

回到顶部