Search code examples
pythonpandasmatplotlibplotdata-science

How to plot multiple pandas columns


I have dataframe total_year, which contains three columns (year, action, comedy).

enter image description here

How can I plot two columns (action and comedy) on y-axis? My code plots only one:

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

enter image description here


Solution

  • Pandas.DataFrame.plot() per default uses index for plotting X axis, all other numeric columns will be used as Y values.

    So setting year column as index will do the trick:

    total_year.set_index('year').plot(figsize=(10,5), grid=True)