我正在尝试使用几个不同的库(bokeh
, seaborn
and matlotlib
),但保持相同的配色方案。我从散景中选择了分类调色板:
from bokeh.palettes import Category10 as palette
然后也用在seaborn
and matplotlib
。我的问题是,虽然在matplotlib
颜色看起来很相似bokeh
(如调色板中定义),seaborn
显示出比应有的明显更深的颜色(即饱和度较低或不饱和)。我想知道它是否默认对任何配色方案进行某种变暗,以及是否有任何方法可以避免这种情况。
下面是使用不同库制作相同条形图的代码
Using bokeh
:
source = pd.DataFrame({'names': ['exp_1', 'exp_2'], 'data':[3, 5], 'color':palette[10][:2]})
p = bokeh.plotting.figure(x_range=['exp_1', 'exp_2'], y_range=(0,6), plot_height=500, title="test")
p.vbar(x='names', top='data', width=0.9, legend_field="names", source=source, color='color')
p.xgrid.grid_line_color = None
p.legend.orientation = "horizontal"
p.legend.location = "top_center"
p.xaxis.major_label_text_font_size = '22pt'
p.yaxis.major_label_text_font_size = '22pt'
bokeh.io.show(p)
Using matplotlib
:
# same palette both for seaborn and matplotlib (taken from bokeh palette)
sns_palette=sns.color_palette(palette[10])
fig, ax = plt.subplots()
plt.style.use('seaborn')
ax.set_xlabel('experiment', fontsize=20)
ax.tick_params(axis='both', which='major', labelsize=22)
ax.set_xticks([0, 1])
ax.set_xticklabels(['exp_1', 'exp_2'], fontsize=18)
ax.bar([0, 1], source['data'], align='center', color=sns_palette[:2])
并使用bokeh
:
plt.figure()
ax = sns.barplot(x="names", y="data", data=source, palette=sns_palette[0:2])
ax.set_xlabel('experiment', fontsize=20)
ax.tick_params(axis='both', which='major', labelsize=18)
plt.tight_layout()
bokeh barplot:
matplotlib barplot
seaborn barplot: