pandas
  1. pandas-plotting

Plotting - ( Pandas Plotting )

Heading h2

Syntax

DataFrame.plot(kind='line', x=None, y=None, ax=None,plots=False, sharex=None, sharey=False, layout=None, figsize=None, use_index=True, title=None, grid=None, legend=True, style=None, logx=False, logy=False, loglog=False, xticks=None, yticks=None, xlim=None, ylim=None, rot=None, fontsize=None, colormap=None, table=False, yerr=None, xerr=None, secondary_y=False, sort_columns=False)

Example

import pandas as pd
import matplotlib.pyplot as plt

data = {'year': [2010, 2011, 2012, 2013, 2014, 2015],
        'sales': [250, 356, 568, 287, 345, 456]}
df = pd.DataFrame(data)

df.plot(kind='line', x='year', y='sales')

plt.show()

Output

A line plot of the data is generated and displayed using the Matplotlib library.

Explanation

Pandas provides various functions for creating and visualizing data. The plot() method in pandas can be used to create different types of plots such as line plots, scatter plots, and bar plots. The kind parameter specifies the type of plot to be generated. In this example, we use a line plot to visualize the sales data over a period of six years.

We use Matplotlib to display the plot using the plt.show() function.

Use

Data visualization is an important aspect of data analysis and the plot() method in pandas makes it easy to visualize data in a variety of ways. Plots can help in understanding trends, patterns, and relationships in data.

Important Points

  • The plot() method in pandas is used for creating different types of plots
  • The kind parameter specifies the type of plot to be generated
  • Line plots, scatter plots, and bar plots are some commonly used plot types
  • Matplotlib can be used to display the plot using the plt.show() function

Summary

In conclusion, the plot() method in pandas provides an easy way to create different types of plots such as line plots, scatter plots, and bar plots. Plots can be used for visualizing trends, patterns, and relationships in data. Matplotlib can be used to display the plots generated using the plot() method.

Published on: