下面的问题解释了如何更改图例的背景颜色:matplotlib legend background color。但是,如果我使用seaborn,这将不起作用。有没有办法做到这一点?
import matplotlib.pyplot as plt
import numpy as np
a = np.random.rand(10,1)
plt.plot(a, label='label')
legend = plt.legend()
frame = legend.get_frame()
frame.set_facecolor('green')
plt.show()
import seaborn as sns
plt.plot(a, label='label')
legend = plt.legend()
frame = legend.get_frame()
frame.set_facecolor('green')
plt.show()
发布于 2015-06-09 23:28:48
seaborn默认关闭图例框架,如果你想自定义框架的外观,我认为当你调用plt.legend
时,你需要添加frameon=True
。
发布于 2017-08-31 17:10:21
set_style()
方法可以接受样式参数(例如'white'
、'whitegrid'
、'darkgrid'
等)。以及覆盖默认美学的参数字典,包括是否启用图例框架。
如果您有其他想要更改的小样式设置,就像我经常做的那样,您可以按照这种方式一次性设置它们。
import seaborn
seaborn.set_style('darkgrid', {'legend.frameon':True})
根据the docs,您可以使用seaborn.axes_style()
获取seaborn
的当前rc
设置
{'axes.axisbelow': True,
'axes.edgecolor': '.8',
'axes.facecolor': 'white',
'axes.grid': True,
'axes.labelcolor': '.15',
'axes.linewidth': 1.0,
'figure.facecolor': 'white',
'font.family': [u'sans-serif'],
'font.sans-serif': [u'Arial',
u'DejaVu Sans',
u'Liberation Sans',
u'Bitstream Vera Sans',
u'sans-serif'],
'grid.color': '.8',
'grid.linestyle': u'-',
'image.cmap': u'rocket',
'legend.frameon': False,
'legend.numpoints': 1,
'legend.scatterpoints': 1,
'lines.solid_capstyle': u'round',
'text.color': '.15',
'xtick.color': '.15',
'xtick.direction': u'out',
'xtick.major.size': 0.0,
'xtick.minor.size': 0.0,
'ytick.color': '.15',
'ytick.direction': u'out',
'ytick.major.size': 0.0,
'ytick.minor.size': 0.0}
https://stackoverflow.com/questions/30729473
复制相似问题