English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Matplotlib 3D surface plot

This surface plot displays the functional relationship between the specified dependent variable (Y) and two independent variables (X and Z). This graph is an accompanying graph of the contour plot. The surface plot is similar to the wireframe plot, but each face of the wireframe is filled with a polygon. This can help perceive the topology of the visualized surface. The plot_surface() function takes x, y, and z as parameters.

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
#! /usr/bin/env python
 #coding=utf-8
 import matplotlib.pyplot as plt
 import numpy as np
 import math
 import seaborn as sns
 plt.rcParams['font.sans-serif'] = ['SimHei']  # Step one (replace sans-serif font)
 plt.rcParams['axes.unicode_minus'] = False  # The original text is from [Lidi Huo], please contact the author for commercial use and retain the original link for non-commercial use:
 from mpl_toolkits import mplot3d
 x = np.outer(np.linspace(-2, 2, 30), np.ones(30))
 y = x.copy().T  # transpose
 z = np.cos(x ** 2 + y ** 2)
 fig = plt.figure()
 ax = plt.axes(projection='3d')
 ax.plot_surface(x, y, z, cmap='viridis', edgecolor='none')
 ax.set_title('Surface Plot')
 plt.show()

Execute the above example code to get the following results -