3D Contour Plotting in Python using Matplotlib Last Updated : 21 Apr, 2020 Comments Improve Suggest changes Like Article Like Report Matplotlib was introduced keeping in mind, only two-dimensional plotting. But at the time when the release of 1.0 occurred, the 3d utilities were developed upon the 2d and thus, we have 3d implementation of data available today! The 3d plots are enabled by importing the mplot3d toolkit. Let's look at a 3d contour diagram of a 3d cosine function. The code is attached for reference. Function Arguments Description meshgrid Function of numpy used to create a rectangular grid out of two given one-dimensional arrays representing the Cartesian indexing or Matrix indexing plt.axes() To create object of the axis ax.contour3D To form the contour ax.set_xlabel To label the X-axis ax.set_title To give a title to the plot Example 1: Python3 from mpl_toolkits import mplot3d import numpy as np import matplotlib.pyplot as plt from matplotlib import cm import math x = [i for i in range(0, 200, 100)] y = [i for i in range(0, 200, 100)] X, Y = np.meshgrid(x, y) Z = [] for i in x: t = [] for j in y: t.append(math.cos(math.sqrt(i*2+j*2))) Z.append(t) fig = plt.figure() ax = plt.axes(projection='3d') ax.contour3D(X, Y, Z, 50, cmap=cm.cool) ax.set_xlabel('a') ax.set_ylabel('b') ax.set_zlabel('c') ax.set_title('3D contour for cosine') plt.show() Output: Example 2: Let's look at another 3d diagram for better understanding of the concept. This time, of a 3d tan function. Python3 from mpl_toolkits import mplot3d import numpy as np import matplotlib.pyplot as plt from matplotlib import cm import math x = [i for i in range(0, 200, 100)] y = [i for i in range(0, 200, 100)] X, Y = np.meshgrid(x, y) Z = [] for i in x: t = [] for j in y: t.append(math.tan(math.sqrt(i*2+j*2))) Z.append(t) fig = plt.figure() ax = plt.axes(projection='3d') ax.contour3D(X, Y, Z, 50, cmap=cm.cool) ax.set_xlabel('a') ax.set_ylabel('b') ax.set_zlabel('c') ax.set_title('3D contour for tan') plt.show() Output: Comment More info H harshp Follow Improve Article Tags : Python Python-matplotlib Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 7 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 6 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like