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

Matplotlib 3D surface plot

The 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 a filled 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 : pt.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 # Original text from 【立地货】,for commercial redistribution, please contact the author for authorization. For non-commercial use, please retain the original link:
 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('Gráfico de Superfície')
 plt.show()

Executar o código de exemplo acima, obter os seguintes resultados -