Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用两种颜色分离seaborn条形图_Python_Plot_Seaborn - Fatal编程技术网

Python 用两种颜色分离seaborn条形图

Python 用两种颜色分离seaborn条形图,python,plot,seaborn,Python,Plot,Seaborn,我有以下数据集: words = ['upvoted', 'upvote', 'f***', 'reimer', 'feminists', 'censorship', 'wet', '0001f914', 'turtle', '0001f602', 'vegans', 'thumbnail', 'lobby', 'mods', 'removed', 'bitches', 'saffron', 'broadband', 'hitler', 'ass', '

我有以下数据集:

words = ['upvoted', 'upvote', 'f***', 'reimer', 'feminists', 'censorship',
       'wet', '0001f914', 'turtle', '0001f602', 'vegans', 'thumbnail',
       'lobby', 'mods', 'removed', 'bitches', 'saffron', 'broadband',
       'hitler', 'ass', 'deleted', 'u', 'tits', 'cheating', 'antifa',
       'iâ', 'â', 'itâ', 'donâ', 'edit', 'thatâ', 'isnâ', 'doesnâ',
       'didnâ', 'canâ', 'youâ', 'theyâ', 'eli5', 'weâ', 'arenâ', 'thereâ',
       'hi', 'wouldnâ', '½ï', 'whatâ', 'ï', '½', 'wasnâ', 'wonâ',
       'eclipse'] 

coefs = [ 1.00157191,  0.95931338,  0.92066619,  0.86347946,  0.83977936,
        0.83912351,  0.83482245,  0.8148754 ,  0.79982483,  0.79402501,
        0.7687297 ,  0.76765479,  0.76096785,  0.75893433,  0.75177131,
        0.74486391,  0.73244163,  0.71302245,  0.70449932,  0.70346844,
        0.69737316,  0.67902944,  0.6746799 ,  0.67338842,  0.6678747 ,
       -2.83723585, -2.82874502, -2.59032368, -2.52985115, -2.1811188 ,
       -1.87094025, -1.66191757, -1.64283967, -1.62282287, -1.61855926,
       -1.55062817, -1.54397537, -1.39775882, -1.3492324 , -1.30638486,
       -1.29859752, -1.14761071, -1.0673105 , -1.06272808, -1.02998239,
       -0.96635257, -0.94262438, -0.91244845, -0.90765028, -0.87274524]
我想做一个有两种颜色的条形图,一种是负值,一种是正值

我的努力使我:

sns.set(rc={'figure.figsize':(20,10)})
sns.set(font_scale = 1.5)
g = sns.barplot(words,coefs, palette =sns.diverging_palette(220, 20, n=50, center = "dark"))
plt.xticks(rotation=90)
plt.show()
但即使在这里,我也不能真正地把它们分开,它只是一个颜色的刻度


你对seaborn的颜色理解有点错误:)

Seaborn的配色方案正在重复。例如,让我们使用以下调色板:

sns.发散调色板(220,20,n=20,center=“dark”)

我们将得到这个图:

如果不希望重复效果,则应为每个条指定
色调
(如果不这样做,
y
将用作
色调
):

colors=[1如果c>=0,则为0对于coefs中的c]

并将其发送到条形图:

g = sns.barplot(
    x=words,
    y=coefs,
    hue=colors, # Here I am!
    palette=sns.color_palette() # Default palette is far better for it
)
因此,您将获得您需要的: