Saturday, 19 August 2023

Introduction to matplotlib

Matplotlib is a widely used library for data visualizations in Python. You can create static, interactive, and animated visualizations in a wide range of formats. Matplotlib is heavily used in data science, Machine learning, Finance, Engineering fields etc.,

 

Following are the key features of Matplotlib.

a.   Easy to use: Learning curve is very minimal and the interface is very easy to starts with.

b.   Support wide variety of visualizations: Supports a wide variety of plot types, including line plots, bar plots , scatter plots, histograms, 3D plots, and more.

c.    Compatibility with Python libraries: Works well with Python libraries like NumPy, Pandas.

d.   LaTeX support: LaTeX is a markup language to produce the documents that contain complex mathematical equations. You can use LaTeX statements for mathematical expressions in labels, titles, and annotations in charts.

e.   Plots can be exported to various different formats.

f.     We can embed the plots in web applications.

 

Is Matplotlib free to use?

Yes, it is open source and free to use.

 

hello_world.py

import matplotlib.pyplot as plt

# Sample data
year = [2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022]
population = [1246.2, 1262.6, 1279.7, 1297.4, 1315.8, 1334.9, 1354.7, 1374.2, 1407.6, 1417.2]

# Create a line plot
plt.plot(year, population)

# Add labels and title
plt.xlabel('Year')
plt.ylabel('Population in Millions')
plt.title('India Population')

# Display the plot
plt.show()

 

Output

 

 



What is plot?

"plot" represents a graphical representation of data. Following are common plot types.

a.   Line plot

b.   Bar plot

c.    Scatter plot

d.   Pie Chart

e.   Histogram

f.     Heatmap

g.   Area plot

h.   Box plot etc.,

Previous                                                    Next                                                    Home

No comments:

Post a Comment