Issue
I have a DataFrame as shown below. The Columns 0:00, 1:00.. till 24:00 represents the hours. How can I plot the hourly variation of both Items 'foo' and 'bar' for all the dates?
Date Item 0:00 1:00 2:00 3:00 4:00 5:00 6:00
1/1/2022 foo 2 3 4 1 5 1.5 2.5
1/2/2022 foo 1.5 1 3 2 2.5 6 4
1/3/2022 foo 1 2 3 1 2 5 4
1/4/2022 foo 2 1 3 4 1 2.4 3
1/1/2022 bar 3 1 0 1.5 5 1.5 2.5
1/2/2022 bar 2.5 4 3 1 2.5 0 1
1/3/2022 bar 1 2 1 1 2 1.5 4
1/4/2022 bar 2 1 3 2 1 2.5 3
I tried the following
g = sns.FacetGrid(df,row='Item',col='Date')
g.map(sns.#someplot,) # within map not sure what plot should I use and how to represent x axis as the columns
Solution
If need bars with separate plots for Item
s use:
df1 = df.melt(['Date','Item'])
g = sns.FacetGrid(df1, row='Item', col="Date")
g.map_dataframe(sns.barplot, x="variable", y="value")
Or if need both Items
in one graph use:
df1 = df.melt(['Date','Item'])
g = sns.FacetGrid(df1, col="Date")
g.map_dataframe(sns.barplot, x="variable", y="value", hue="Item")
Answered By - jezrael
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.