# How to plot two columns of single DataFrame on Y axis

I have two data frames (Action, Comedy). Action contains two columns (year, rating) ratings columns contains average rating with respect to year. The Comedy data frame contains the same two columns with different mean values.

I merged both data frames into a total_year data frame.

The output of total_year:

Now, I would like to plot total_year on a line graph in which the X axis should contain the year column and the Y axis should contain both the action and the comedy columns.

I can plot only 1 column at a time on Y axis using following code:

total_year[-15:].plot(x='year', y='action' ,figsize=(10,5), grid=True)


How can I plot both columns on the Y axis?

I took this photo from google just to let you know guys I want to draw graph in this way:

• i got answer of this Question here Dec 12 '17 at 14:58

Feeding your column names into the y values argument as a list works for me like so:

total_year[-15:].plot(x='year', y=['action', 'comedy'], figsize=(10,5), grid=True)


Using something like the answer at this link is better and gives you way more control over the labels and whatnot: adding lines with plt.plot()

Using Seaborn:

Need to melt down columns so that they can be treated as hue in plotting

    import seaborn as sns
df_melted = df.melt("year",var_name="Action&Comedy",value_name="Rating")


    sns.relplot(data=df_melt, x="year", y="Rating", hue="Action&Comedy",kind="line", height=4, aspect=.7)



• Is there a way that doesn't involve melting? In my case, I have one column for the hue (which algorithm I'm running), one column for the score (which I'd like plotted on the Y axis) and a third column for the optimal possible score (which I'd like added as another line). How could I do this? Dec 29 '21 at 18:47