Skip to main content
SAGE
Search form
  • 00:05

    GARY WHITE: We're going to go over using a 3D surface plot asopposed to a contour plot.So in the previous tutorial, we created a function whichis the exact same as this.So it was x squared and y squared and takingthe square root of that, and thenputting it into a sine value.And this gave us this equation, this plot that we have here.

  • 00:29

    GARY WHITE [continued]: And the values were linearly spaced from minus 6 to 6,and then we created this mesh grid.And so using the contour plot, wewere able to create this contour plot.And you can see all of the contours going in circles.Let's say if we wanted to just create the surface insteadof a contour plot.So then we could use an actual plot surface function.

  • 00:53

    GARY WHITE [continued]: And that's what we're going to create in this tutorial.So I've set up the function and created all the data points.So all we need to do now is to set up our figure environmentand start plotting.So we do figure equal to plt.figure().And then our axis is equal to plt.axis.

  • 01:20

    GARY WHITE [continued]: And we want to set our projection equal to 3D again.And then we can start our plot surface.So we do ax.plot_surface.

  • 01:42

    GARY WHITE [continued]: And then we specify the values that we wantto plot, which is x, y, and z.We then specify our strides.So the rstride is equal to 1, and the cstride is equal to 1.

  • 02:04

    GARY WHITE [continued]: And then we choose the color map that we want to use.So this we're going to choose cmap equal to viridis,so V-I-R-I-D-I-S. And we're going to set our edge colorequal to none.

  • 02:30

    GARY WHITE [continued]: And finally then, we're just goingto set our title equal to surface.So ax.set_title, and set that equal to surface.So then we can show our plot using plt.plot() or plt.show().

  • 02:53

    GARY WHITE [continued]: And if we run this, you can see nowthat we've got a surface plot as opposed to the contour plot.And it just gives us a better, or sortof a different view on the contour plotby showing us the actual surface.So these are both really good ways

  • 03:14

    GARY WHITE [continued]: of creating these 3D visualizations.And they can be really good for graphing more complicatedfunctions that are in 3D.

Video Info

Series Name: Data Visualization With Matplotlib 3.x and Python

Episode: 45

Publisher: Gary White

Publication Year: 2020

Video Type:Tutorial

Methods: Data visualization, Python, Coding

Keywords: coding; data visualisation; graphical presentation of data

Segment Info

Segment Num.: 1

Persons Discussed:

Events Discussed:

Keywords:

Abstract

Gary White explains how to create a 3D surface plot in Matplotlib.

Looks like you do not have access to this content.

3D Surface Plots

Gary White explains how to create a 3D surface plot in Matplotlib.

Copy and paste the following HTML into your website