简体   繁体   中英

Histogram with Python

I have a dataframe df_Ratio with this structure

class_energy ACT_TIME_AERATEUR_1_F1 ACT_TIME_AERATEUR_1_F3 ACT_TIME_AERATEUR_1_F5 ACT_TIME_AERATEUR_1_F6 ACT_TIME_AERATEUR_1_F7 ACT_TIME_AERATEUR_1_F8
high 0.166667 0.166667 0.166667 0.166667 0.166667 0.166667 
low 0.166964 0.167003 0.167081 0.166935 0.166058 0.165961 
medium 0.167268 0.167400 0.167165 0.167334 0.165224 0.165609

I need to create a histogram concerning only high rows :

In the x axis ACT_TIME_AERATEUR_1_F5 ACT_TIME_AERATEUR_1_F6 ACT_TIME_AERATEUR_1_F7 ACT_TIME_AERATEUR_1_F8

and the y axis represents the values : "0.166667 0.166667 0.166667 0.166667 0.166667 0.166667 "

Any idea please?

I'm not sure if I got everything right, but here is a working example:

import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('data.txt', sep=' ')
df = df.T         # transpose dataframe

plt.bar(range(len(df.high)-1), df.high[1:], align='center')
plt.xticks(range(len(df.high)-1), df.index[1:], size='small')
plt.xticks(rotation=90)

plt.tight_layout()
plt.show()

Probably you have to adjust the data range by [1:] , depending on how exactly your data looks and on what you want to plot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM