0
votes

I have two DataFrames like below. Both have the same structure (columns names and index) but different values. DataFrame 1 is observed values and DataFrame 2 is predicted. I wanted to draw a single figure using subplots each representing one of the columns, Y- axis to be the values from both dataframes ( two different lines) and X-axis the index.

I know that I am supposed to post sample codes of my work but it seems they are all wrong, that is why I am not sharing my sample code. I really want to use something like the sns.FacetGrid of seaborn as the plots have higher qualities.

    08FB006 08FC001 08FC003 08FC005 08GD004
----------------------------------------------
0   253      872    256      11.80    2660
1   250      850    255      10.60    2510
2   246      850    241      10.30    2130
3   241      827    235      9.32     1970
4   241      821    229      9.17     1900
5   232      819    228      8.93     1840
6   231      818    225      8.05     1710
7   234      817    225      7.90     1610
8   210      817    224      7.60     1590
9   200      816    221      7.53     1590
10  199      810    219      7.41     1550
1

1 Answers

1
votes

You can modify below code according to your needs -

actual = pd.DataFrame({'a': [5, 8, 9, 6, 7, 2],
                       'b': [89, 22, 44, 6, 44, 1]})
predicted = pd.DataFrame({'a': [7, 2, 13, 18, 20, 2],
                       'b': [9, 20, 4, 16, 40, 11]})

# Creating a tidy-dataframe to input under seaborn
merged = pd.concat([pd.melt(actual), pd.melt(predicted)]).reset_index()
merged['category'] = ''
merged.loc[:len(actual)*2,'category'] = 'actual'
merged.loc[len(actual)*2:,'category'] = 'predicted'

g = sns.FacetGrid(merged, col="category", hue="variable")
g.map(plt.plot, "index", "value", alpha=.7)
g.add_legend();

plt