这是一段测试seaborn调色板的代码:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sb
print("Seaborn version : {0}".format(sb.__version__))
# Seaborn version : 0.10.0
print("Matplotlib version : {0}".format(matplotlib.__version__))
# Matplotlib version : 3.1.3
只是为了让您知道它适用于这些版本
# simple color test without palette
n = 1000
x = np.arange(1,n+1,1)
y = np.random.randint(-100,100,n)*np.random.random(n)
sb.barplot(x,y)
plt.xticks([])
plt.show()
# with your color choices
plt.figure(figsize=(20,20))
sb.barplot(x,y, palette=sb.color_palette("RdBu",n_colors=7))
plt.xticks([])
plt.show()
所以它似乎适用于我的代码数组。
也许:
希望这会有所帮助!
编辑:
感谢@ImportanceOfBeingErnest,我想我理解了你的问题。就是从这个风格来的,评论/取消评论就可以看到结果了
# sb.set_style("darkgrid")
遗憾的是,我没有找到任何与 darkgrid 样式相关的 kwargs 选项来消除错误...所以我建议我们手动重新创建此样式!
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_facecolor('whitesmoke')
# background color
ax.grid(color='white', linestyle='-', linewidth=1)
# the grid
sb.barplot(x,y,zorder=2, palette=sb.color_palette("RdBu",n_colors=7))
#zorder=2 to draw above the grid
plt.xticks([])
plt.show()