Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting histogram for all features with titles

I wrote the following code to plot histograms of all the features in my dataframe dff. My code snippet:

import matplotlib.pyplot as plt
dff.head()
for i in dff.columns:
        plt.figure()
        plt.hist(dff[i])

However the histograms just get plotted without the feature name / column name.Is there a way i could also print the column name below each of distribution charts so that i can relate which distribution corresponds to which column?

like image 249
siya m Avatar asked Oct 13 '25 06:10

siya m


1 Answers

this is the first time I actually got chance to answer a question.

if you add this line it will print the column name as the title, you can add other text to it as well. This is a super useful little function

plt.title(f'{i}')

here is it in your code

dff.head()
for i in dff.columns:
    
    plt.figure()
    plt.title(f'{i}')
    plt.hist(dff[i])

*edited this as I put the title in the wrong place originally

like image 105
Tantable Avatar answered Oct 14 '25 19:10

Tantable