I am trying to learn the seaborn object Plot()
interface. With the traditional sns.barplot()
we could easily define color palette for the bars.
import seaborn as sns
df = sns.load_dataset('penguins')
sns.barplot(df, x='species', y='body_mass_g', palette='YlGnBu')
However, When I am trying to achieve the same with the use of Plot(),
so.Plot(df, x='species', y='body_mass_g').add(so.Bar(palette='YlGnBu'),so.Agg())
I am getting the following error:
TypeError: Bar.__init__() got an unexpected keyword argument 'palette'
I could able to assign colors to the bars by declaring color='species'
and passing the color list in scale()
.
so.Plot(df, x='species', y='body_mass_g').add(so.Bar(),so.Agg(),color='species').scale(color=['Yellow','Green','Blue'])
However, this comes with a legend. I tried to remove the legend by plt.legend_.remove()
, but it's not working.
You can suppress each layer from the legend when you call Plot.add
. As an aside, you can also set a named palette for the color scale:
import seaborn as sns
df = sns.load_dataset('penguins')
(
so.Plot(df, x='species', y='body_mass_g')
.add(so.Bar(),so.Agg(), color='species', legend=False)
.scale(color="YlGnBu")
)