Python 使用 matplotlib 删除或调整图例框架的边框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25540259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove or adapt border of frame of legend using matplotlib
提问by Mattijn
When plotting a plot using matplotlib:
使用 matplotlib 绘制绘图时:
- How to remove the box of the legend?
- How to change the color of the border of the legend box?
- How to remove only the border of the box of the legend?
- 如何去除图例的框?
- 如何更改图例框边框的颜色?
- 如何仅删除图例框的边框?
采纳答案by Mattijn
When plotting a plot using matplotlib:
使用 matplotlib 绘制绘图时:
How to remove the box of the legend?
如何去除图例的框?
plt.legend(frameon=False)
How to change the color of the border of the legend box?
如何更改图例框边框的颜色?
leg = plt.legend()
leg.get_frame().set_edgecolor('b')
How to remove only the border of the box of the legend?
如何仅删除图例框的边框?
leg = plt.legend()
leg.get_frame().set_linewidth(0.0)
回答by Kevin J. Black
One more related question, since it took me forever to find the answer:
还有一个相关的问题,因为我花了很长时间才找到答案:
How to make the legend background blank (i.e.transparent, not white):
如何使图例背景空白(即透明,而不是白色):
legend = plt.legend()
legend.get_frame().set_facecolor('none')
Warning, you want 'none'(the string). Nonemeans the default color instead.
警告,你想要'none'(字符串)。None表示默认颜色。

