pottigopi
pottigopi

Reputation: 21

How to reduce the font of the text in the legend box printed in the plot?

I am trying to plot around 10 plots in a single figure. I also could put the legend box separately. But, I am unable to reduce the size of the font in the legend box. Can anybody suggest me the procedure to reduce the font size in the lengend box.

I am herewith giving the instructions that I have used: But it is not getting affected in the end result.

# Shink current axis's height by 10% on the bottom
  box = ax.get_position()
  ax.set_position([box.x0, box.y0, box.width * 0.90, box.height])

  # Put a legend to the right of the current axis
  ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), numpoints = 1)
  #plt.show()

  fontP = FontProperties()
  fontP.set_size ('x-small')

  filename1 = "DelayCellSpur"+ str(measuredFrequencyUnderTest)+"MHz.pdf"
  print filename1
  plt.savefig(filename1, dpi = None, facecolor = 'w', orientation = 'portrait',bbox_inches = None)

As I am a new user, I am not able to upload the image. Pls help me in reducing the size of the font in the legend box. Thankyou, Gopi

Upvotes: 2

Views: 3002

Answers (1)

9000
9000

Reputation: 40904

You're using matplotlb, aren't you?

Something like this may help:

legend_font_props = FontProperties()
legend_font_props.set_size('small')
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), numpoints=1, prop=legend_font_props)

See http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.legend

Upvotes: 2

Related Questions