Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching axis while generating histogram using data frames

index_size= 10
column_size = 1
df = pd.DataFrame(np.zeros((index_size, column_size)))
df.columns = ['Value']
df.iat[0,0] = 5
df.iat[1,0] = 6
df.iat[5,0] = 8
df.hist(column='Value')

I get the below graph with 'Value' on X-axis and indices (0-9) on Y-axis but i want indices on X-axis and 'Value' on Y-axis.

enter image description here

I am expecting a graph like below:

enter image description here

like image 254
moooni moon Avatar asked Aug 05 '26 14:08

moooni moon


1 Answers

Use parameter orientation, unfortunately it not in DataFrame.plot.hist documentation, because it contains last kwds parameter.

Parameter is possible find in matplotlib.pyplot.hist.

df.hist(column='Value', orientation="horizontal")

graph

EDIT:

Histogram plot counted values:

print (df['Value'].value_counts())
0.0    7
8.0    1
6.0    1
5.0    1
Name: Value, dtype: int64

If need plot bar or barh:

df.plot.bar()

graph


df.plot.barh()

graph

like image 74
jezrael Avatar answered Aug 08 '26 05:08

jezrael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!