Matplotlib 3D WireFrame Plot – plot_wireframe() Function

For the data visualization using 3D wireframe, we require some modules from matplotlibmpl_toolkits and numpy library.

The wireframe plot basically takes a grid of values and projects it onto the specified 3-dimensional surfaces, and it can help in making the resulting three-dimensional forms quite easy for visualization.

To create the 3D Wireframe plot the plot_wireframe() function will be used.

Now its time to cover few examples for the 3D wireframe plot.

3D Wireframe Plot Basic Example:

Below we have an example where we will create a 3D Wireframe plot:

from mpl_toolkits.mplot3d import axes3d 
from matplotlib import pyplot 

fig = pyplot.figure() 
wf = fig.add_subplot(111, projection='3d') 
x, y, z = axes3d.get_test_data(0.07) 
wf.plot_wireframe(x,y,z, rstride=2, cstride=2, color='maroon') 

wf.set_title('3D wireframe plot') 
pyplot.show() 

Here is the output of the above code:

3d wireframe plot basic example

3D Wireframe Plot Example 2:

Here is another example and code snippet for the same is given below:

from mpl_toolkits import mplot3d 
import numpy 

a = numpy.linspace(-5, 5, 25) 
b = numpy.linspace(-5, 5, 25) 
x, y = numpy.meshgrid(a, b) 
z = numpy.cos(numpy.sqrt(x**2 + y**2)) 

fig = pyplot.figure() 
wf = pyplot.axes(projection ='3d') 
wf.plot_wireframe(x, y, z, color ='blue') 

wf.set_title('Example 2') 
pyplot.show() 

Here is the output of the above code:

Follow Us On