【发布时间】:2014-10-21 19:28:49
【问题描述】:
使用 matplotlib 绘制绘图时:
- 如何去掉图例的框?
- 如何改变图例框的边框颜色?
- 如何只去掉图例框的边框?
【问题讨论】:
标签: python matplotlib
使用 matplotlib 绘制绘图时:
【问题讨论】:
标签: python matplotlib
使用 matplotlib 绘制绘图时:
如何去掉图例的框?
plt.legend(frameon=False)
如何改变图例框边框的颜色?
leg = plt.legend()
leg.get_frame().set_edgecolor('b')
如何只去掉图例框的边框?
leg = plt.legend()
leg.get_frame().set_linewidth(0.0)
对于matplotlib 面向对象的方法:
axes.legend(frameon=False)
leg = axes.legend()
leg.get_frame().set_edgecolor('b')
leg.get_frame().set_linewidth(0.0)
【讨论】:
还有一个相关的问题,因为我花了很长时间才找到答案:
如何使图例背景为空白(即透明,而不是白色):
legend = plt.legend()
legend.get_frame().set_facecolor('none')
警告,您需要'none'(字符串)。 None 表示默认颜色。
【讨论】:
framealpha,即plt.legend(framealpha=0.0)。不过,这将包括盒子