
- Python Data Science - Home
- Python Data Science - Getting Started
- Python Data Science - Environment Setup
- Python Data Science - Pandas
- Python Data Science - Numpy
- Python Data Science - SciPy
- Python Data Science - Matplotlib
- Python Data Operations
- Python Data cleansing
- Python Processing CSV Data
- Python Processing JSON Data
- Python Processing XLS Data
- Python Relational databases
- Python NoSQL Databases
- Python Date and Time
- Python Data Wrangling
- Python Data Aggregation
- Python Reading HTML Pages
- Python Processing Unstructured Data
- Python word tokenization
- Python Stemming and Lemmatization
- Python Data Visualization
- Python Chart Properties
- Python Chart Styling
- Python Box Plots
- Python Heat Maps
- Python Scatter Plots
- Python Bubble Charts
- Python 3D Charts
- Python Time Series
- Python Geographical Data
- Python Graph Data
Python Data Science - Matplotlib
What is Matplotlib?
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 feature 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 on using Matplotlib library of python in Data science work in the next chapters.