Visualizing values in a normalized plot

Viewed 116

I have some data that I would like to plot, visualizing in a normalized chart. Dataset:

            Gini
    var1    0.000223
    var2    0.000047
    var3    0.000933
    var4    0.000081
    var5    0.000014

df.sort_values(by='Gini', ascending=False).plot(kind='bar')

I have tried with plt.yticks(np.arange(0, 1)) but this just changes the scale.

1 Answers

If you're having a single column and plotting only the "Gini" column, you can select that column and normalize it before plotting it like:

((df['Gini']-df['Gini'].min())/(df['Gini'].max()-df['Gini'].min())).sort_values().plot(kind='bar')

In general, you can normalize the whole dataframe and plot it:

df_normalized = (df-df.min())/(df.max()-df.min())
df_normalized.sort_values(by='Gini', ascending=False).plot(kind='bar')
Related