I am plotting following type of Bar Plot using SNS using the following code. I used cubehelix_palette
as I want the bar color intensities according to the values. I am expecting the higher values get darker purple and lower values get lighter. But It seems very different what I am getting here. . It seems less negative values are getting darker and more positive value is neglected. Am I doing something wrong here?
x = ["A","B","C","D"]
y = [-0.086552691,0.498737914,-0.090153413,-0.075941404]
sns.axes_style('white')
sns.set_style('white')
pal=sns.cubehelix_palette(5)
ax = sns.barplot(x, y,palette=pal)
for n, (label, _y) in enumerate(zip(x, y)):
ax.annotate(
s='{:.3f}'.format(_y),
xy=(n, _y),
ha='center',va='center',
xytext=(0,10*(1 if _y > 0 else -1)),
textcoords='offset points',
size = 8,
weight='bold'
)
ax.annotate(
s=label,
xy=(n, 0),
ha='left',va='center',
xytext=(0,50*(-1 if _y > 0 else 1)),
textcoords='offset points',
rotation=90,
size = 10,
weight='bold'
)
# axes formatting
#ax.set_yticks([])
ax.set_xticks([])
sns.despine(ax=ax, bottom=True, left=True)
EDITED
As per @ImportanceOfBeingErnest suggestion, I tried the following code too. However, the negative directional intensities are wrong. Also disturbing Legend is also visible.
import numpy as np, matplotlib.pyplot as plt, seaborn as sns
sns.set(style="whitegrid", color_codes=True)
pal = sns.color_palette("Greens_d", 5)
ax = sns.barplot(x=x, y=y, palette=pal,hue=y,dodge=False)
x = ["A","B","C","D","E","F","G","H","I","J","K"]
y = [-0.086552691,
0.498737914,
-0.090153413,
-0.075941404,
-0.089105985,
-0.05301275,
-0.095927691,
-0.083528335,
0.250680624,
-0.092506638,
-0.082689631,
]
for n, (label, _y) in enumerate(zip(x, y)):
ax.annotate(
s='{:.3f}'.format(_y),
xy=(n, _y),
ha='center',va='center',
xytext=(0,10*(1 if _y > 0 else -1)),
textcoords='offset points',
size = 8,
weight='bold'
)
ax.annotate(
s=label,
xy=(n, 0),
ha='left',va='center',
xytext=(0,50*(-1 if _y > 0 else 1)),
textcoords='offset points',
rotation=90,
size = 10,
weight='bold'
)
ax.set_xticks([])
sns.despine(ax=ax, bottom=True, left=True)
plt.show()