How can I plot the top 5 values that appear to be the biggest in this plot? (Wii
,NES
,GB
,DS
,X360
)
sns.violinplot(x=df['Global_Sales'],y=df['Platform'],data=df)
CodePudding user response:
Make sure x
and y
are column names‡ and then sort/filter the data
argument:
Either use
nlargest
(fastest):sns.violinplot( x='Global_Sales', y='Platform', data=df.nlargest(5, 'Global_Sales') )
Or
sort_values
withtail
:... data=df.sort_values('Global_Sales').tail(5)
Or
sort_values(ascending=False)
withhead
:... data=df.sort_values('Global_Sales', ascending=False).head(5)
‡ In OP's code, x
and y
are column data (x=df['Global_Sales']
) instead of column names (x='Global_Sales'
). If x
and y
are actual data, the data
param is ignored, so df
would need to be sorted/filtered before the plotting command.