Area plot in pandas
pandas is a popular Python-based data analysis toolkit that can be imported using:
" import pandas as pd "
It presents a diverse range of utilities from parsing multiple file-formats to converting an entire data table into a NumPy matrix array. This property makes pandas a trusted ally in data science and machine learning.
pandas can help with the creation of multiple types of data analysis graphs. One such graph is the
The default implementation of area plot is:
DataFrame.plot.area( x=None, y = None, stacked =
True, **kwargs)
Parameters
-
x: label or position - x-coordinates. It uses index by default. -
y: label or position - Column to plot. It uses all columns by default. -
stacked: bool - The area plots are stacked. -
**kwargs: tuple (rows, columns) - All other plotting keyword arguments to be passed to DataFrame.plot().
Code
The following code shows how an area plot can be added in Python. You can change different parameters and look at how the output varies.
#import libraryimport pandas as pd#add csv file to dataframedf = pd.read_csv('dataset.csv')#create area plotareaplot = df.plot.area( figsize = (5,5), stacked= False)
Free Resources