- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Matplotlib is a popular Python package that is used for data visualization. Visualizing data is a key step since it helps understand what is going on in the data without actually looking at the numbers and performing complicated computations.

It helps in communicating the quantitative insights to the audience effectively. Matplotlib is used to create 2 dimensional plots with the data. It comes with an object oriented API that helps in embedding the plots in Python applications. Matplotlib can be used with IPython shells, Jupyter notebook, Spyder IDE and so on.

It is written in Python. It is created using Numpy, which is the Numerical Python package in Python.

Python can be installed on Windows using the below command −

pip install matplotlib

The dependencies of Matplotlib are −

Python ( greater than or equal to version 3.4) NumPy Setuptools Pyparsing Libpng Pytz Free type Six Cycler Dateutil

Three dimensional plots are created to view the x−, y− and z−axes of the data points. It can also be used to understand how the gradient descent function works, and to find the optimal values for coefficients for an algorithm.

Let us understand how Matplotlib can be used to create three dimensional line plot −

from mpl_toolkits import mplot3d import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax = plt.axes(projection='3d') z = np.linspace(0, 1, 100) x = z * np.sin(20 * z) y = z * np.cos(20 * z) ax.plot3D(x, y, z, 'red') ax.set_ylabel("Y−axis") ax.set_xlabel("X−axis") ax.set_zlabel("Z−axis") ax.set_title('A sample 3D line plot') plt.show()

The required packages are imported and its alias is defined for ease of use.

An empty figure is created using the ‘figure’ function.

The ‘subplot’ function is used to create an area to plot the graph.

The data values are created using the NumPy library.

The data is plotted using the ‘plot’ function.

The ‘plot3D’ is used to specifying that a 3-dimensional plot is being visualized with the data that has been created.

The set_xlabel, set_ylabel and set_title functions are used to provide labels for ‘X’ axis, ‘Y’ axis and title.

It is shown on the console using the ‘show’ function.

- Related Questions & Answers
- How can Matplotlib be used to create three-dimensional scatter plot using Python?
- How can Pygal be used to generate line plots in Python?
- How can Matplotlib be used to create 3 dimensional contour plot using Python?
- How can Matplotlib be used to create multiple plots iteratively in Python?
- How can matplotlib be used to create histograms using Python?
- How can Bokeh library be used to plot horizontal bar plots using Python?
- How can Pygal be used to generate box plots in Python?
- How can Pygal be used to generate Funnel plots in Python?
- How can Pygal be used to generate Gauge plots in Python?
- How can Pygal be used to generate dot plots in Python?
- How can Tensorflow be used to build a one dimensional convolutional network using Python?
- How can Seaborn library be used to visualize point plots in Python?
- How can Bokeh be used to visualize multiple bar plots in Python?
- How can multiple plots be plotted in same figure using matplotlib and Python?
- How can Seaborn library be used to display categorical scatter plots in Python?

Advertisements