Python uses matplotlib to draw 3D graphics, pythonmatplotlib

Source: Internet
Author: User

Python uses matplotlib to draw 3D graphics, pythonmatplotlib

This example describes how to use matplotlib to draw 3D images in Python. We will share this with you for your reference. The details are as follows:

Code 1:

# Coding = utf-8import numpy as npimport matplotlib. pyplot as pltimport mpl_toolkits.mplot3dx, y = np. mgrid [-2: 2: 20j,-2: 2: 20j] # Test Data z = x * np. exp (-x ** 2-y ** 2) # 3D image ax = plt. subplot (111, projection = '3d ') ax. set_title ('www .jb51.net-matplotlib demo'); ax. plot_surface (x, y, z, rstride = 2, cstride = 1, cmap = plt. cm. blues_r) # Set the axis label ax. set_xlabel ('x') ax. set_ylabel ('y') ax. set_zlabel ('Z') plt. show ()

Running result:

 

Code 2:

# Coding = utf-8import pylab as plimport numpy as npimport mpl_toolkits.mplot3drho, theta = np. mgrid [0: 1: 40j, 0: 2 * np. pi: 40j] z = company ** 2x = company * np. cos (theta) y = company * np. sin (theta) ax = pl. subplot (111, projection = '3d ') ax. set_title ('www .jb51.net-matplotlib demo'); # ax. plot_surface (x, y, z) ax. plot_surface (x, y, z, rstride = 2, cstride = 1) # Set the axis label ax. set_xlabel ('x') ax. set_ylabel ('y') ax. set_zlabel ('Z') pl. show ()

Running result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.