如何减小绘图中图例框中文字的字体?

2 投票
1 回答
2992 浏览
提问于 2025-04-16 10:56

我想在一个图表里画大约10个图。我也可以把图例框单独放。但是,我不知道怎么把图例框里的字体大小调小。有没有人能告诉我怎么做?

我在这里给出我用过的步骤,但最终的结果没有变化。

# 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)

因为我是新用户,所以无法上传图片。请帮我把图例框里的字体大小调小。谢谢,

Gopi

1 个回答

2

你在使用matplotlib,对吧?

像这样做可能会对你有帮助:

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)

可以查看这个链接了解更多信息:http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.legend

撰写回答