[Scientific / technical calculation by Python] Drawing of 3D curved surface, surface, wireframe, visualization, matplotlib

Introduction

Plot the function $ z = e ^ {-(x ^ 2 + y ^ 2)} $ that can be represented by a 3D curved surface using matplotlib. Use plot_surface and plot_wireframe.

code

(1) surface plot

"""
Plot example of 3D curved surface
z=exp(-(x^2+y^2))
"""
from mpl_toolkits.mplot3d import Axes3D   
import matplotlib.pyplot as plt 
import numpy as np

fig = plt.figure() #Creating a plot area
ax = fig.gca(projection='3d') #Get the axes in the plot. gca is"Get Current Axes"Abbreviation for.

x = np.arange(-2, 2, 0.05) #As x points[-2, 2]Up to 0.Sample in 05 increments
y = np.arange(-2, 2, 0.05)  #As y point[-2, 2]Up to 0.Sample in 05 increments
x, y = np.meshgrid(x, y)  #Sampling points mentioned above(x,y)Mesh generation using

z = np.exp(-(x**2 + y**2))  #exp(-(x^2+y^2))Is calculated and stored in the zz coordinates.

ax.plot_surface(x, y, z, rstride=1, cstride=1, cmap='hsv', linewidth=0.3) #Surface plot. rstride and cstride represent the step size, cmap represents coloring, and linewidth represents the line thickness of the curved mesh.

plt.show() #Picture output.

Result (1)

t.png


(2) Wireframe display


from mpl_toolkits.mplot3d import Axes3D   
import matplotlib.pyplot as plt 
import numpy as np

fig = plt.figure() #Creating a plot area
ax = fig.gca(projection='3d') #Get the axes in the plot. gca is"Get Current Axes"Abbreviation for.

x = np.arange(-2, 2, 0.05) #As x points[-2, 2]Up to 0.Sample in 05 increments
y = np.arange(-2, 2, 0.05)  #As y point[-2, 2]Up to 0.Sample in 05 increments
x, y = np.meshgrid(x, y)  #Sampling points mentioned above(x,y)Mesh generation using

z = np.exp(-(x**2 + y**2))  #exp(-(x^2+y^2))Is calculated and stored in the zz coordinates.
ax.set_zlim(0.0,1.0)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
    
ax.plot_wireframe(x, y, z, color='blue',linewidth=0.3) #Wireframe plot. linewidth represents the line thickness of the curved mesh.

plt.show() #Picture output.

Result (2)

tt.png


Recommended Posts

[Scientific / technical calculation by Python] Drawing of 3D curved surface, surface, wireframe, visualization, matplotlib
[Scientific / technical calculation by Python] Drawing, visualization, matplotlib of 2D (color) contour lines, etc.
[Scientific / technical calculation by Python] Plot, visualization, matplotlib of 2D data read from file
[Scientific / technical calculation by Python] Polar graph, visualization, matplotlib
Scientific / technical calculation by Python] Drawing and visualization of 3D isosurface and its cross section using mayavi
[Scientific / technical calculation by Python] Vector field visualization example, electrostatic field, matplotlib
[Scientific / technical calculation by Python] Plot, visualize, matplotlib 2D data with error bars
[Scientific / technical calculation by Python] Basic operation of arrays, numpy
[Scientific / technical calculation by Python] Sum calculation, numerical calculation
[Scientific and technical calculation by Python] Drawing of fractal figures [Sierpinski triangle, Bernsley fern, fractal tree]
[Scientific / technical calculation by Python] Monte Carlo simulation of thermodynamics of 2D Ising spin system by Metropolis method
[Scientific / technical calculation by Python] Fitting by nonlinear function, equation of state, scipy
[Scientific / technical calculation by Python] Inverse matrix calculation, numpy
[Scientific / technical calculation by Python] Lagrange interpolation, numerical calculation
[Scientific / technical calculation by Python] Numerical calculation to find the value of derivative (differential)
[Scientific / technical calculation by Python] Analytical solution to find the solution of equation sympy
[Scientific / technical calculation by Python] Monte Carlo integration, numerical calculation, numpy
[Scientific / technical calculation by Python] Numerical solution of second-order ordinary differential equations, initial value problem, numerical calculation
[Scientific / technical calculation by Python] List of matrices that appear in Hinpan in numerical linear algebra
[Scientific / technical calculation by Python] List of usage of (special) functions used in physics by using scipy
[Scientific / technical calculation by Python] Wave "beat" and group velocity, wave superposition, visualization, high school physics
[Scientific / technical calculation by Python] Numerical solution of one-dimensional harmonic oscillator problem by velocity Verlet method
[Scientific / technical calculation by Python] Numerical solution of eigenvalue problem of matrix by power method, numerical linear algebra
[Scientific / technical calculation by Python] Solving simultaneous linear equations, numerical calculation, numpy
[Scientific / technical calculation by Python] 1D-3D discrete fast Fourier transform, scipy
[Scientific / technical calculation by Python] Derivation of analytical solutions for quadratic and cubic equations, mathematical formulas, sympy
Example of 3D skeleton analysis by Python
[Scientific / technical calculation by Python] Solving ordinary differential equations, mathematical formulas, sympy
[Scientific / technical calculation by Python] Solving the boundary value problem of ordinary differential equations in matrix format, numerical calculation
[Scientific / technical calculation by Python] Solving (generalized) eigenvalue problem using numpy / scipy, using library
[Scientific / technical calculation by Python] Solving one-dimensional Newton equation by the 4th-order Runge-Kutta method
Calculation of technical indicators by TA-Lib and pandas
[Scientific / technical calculation by Python] Numerical solution of one-dimensional and two-dimensional wave equations by FTCS method (explicit method), hyperbolic partial differential equations
[Scientific / technical calculation by Python] Generation of non-uniform random numbers giving a given probability density function, Monte Carlo simulation
python --Export 2D histogram as an array by Matplotlib
[Science / technical calculation by Python] Numerical solution of first-order ordinary differential equations, initial value problem, numerical calculation
Visualization memo by Python
Installation of matplotlib (Python 3.3.2)
[Introduction to Data Scientists] Basics of scientific calculation, data processing, and how to use graph drawing library ♬ Basics of Matplotlib
[Scientific / technical calculation by Python] Numerical solution of one-dimensional unsteady heat conduction equation by Crank-Nicholson method (implicit method) and FTCS method (positive solution method), parabolic partial differential equation