Python - Matplotlib

Rajesh Naik

a year ago

Matplotlib is a python library used to create 2D graphs and plots by using python scripts. It has a module named pyplot which makes things easy for plotting by providing features to control line styles, font properties, formatting axes, etc. It supports a very wide variety of graphs and plots namely - histogram, bar charts, power spectra, error charts, etc. It is used along with NumPy to provide an environment that is an effective open-source alternative for MatLab. It can also be used with graphics toolkits like PyQt and wxPython.
Conventionally, the package is imported into the Python script by adding the following statement −
from matplotlib import pyplot as plt

Matplotlib Example

The following script produces the sine wave plot using matplotlib.

Example


import numpy as np 
import matplotlib.pyplot as plt  

# Compute the x and y coordinates for points on a sine curve 
x = np.arange(0, 3 * np.pi, 0.1) 
y = np.sin(x) 
plt.title("sine wave form") 

# Plot the points using matplotlib 
plt.plot(x, y) 
plt.show() 
Its output is as follows −
We will see lots of examples of using the Matplotlib library of python in data science work in the next chapters. For more learning log in to InsideAIML.

Submit Review

BOT
Agent(Online)
We're Online!

Chat now for any query