Python uses matplotlib to draw a user-defined image function example, pythonmatplotlib

Source: Internet
Author: User

Python uses matplotlib to draw a user-defined image function example, pythonmatplotlib

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

Code 1

From matplotlib. path importPathfrom matplotlib. patches importPathPatchimport matplotlib. pyplot as pltfig, ax = plt. subplots () # define the coordinates of the drawing command and control point # MOVETO indicates that the drawing start point is moved to the specified coordinate # CURVE4 indicates that the beiser curve is drawn three times using four control points # CURVE3 indicates that the three control points are drawn twice. curve # LINETO: draw a straight line from the current position to the specified position # CLOSEPOLY: draw a straight line from the current position to the specified position, and close the polygon path_data = [(Path. MOVETO, (1.58,-2.57), (Path. CURVE4, (0.35,-1.1), (Path. CURVE4, (-1.75, 2.0), (Path. CURVE4, (0.375, 2.0), (Path. LINETO, (0.85, 1.15), (Path. CURVE4, (2.2, 3.2), (Path. CURVE4, (3, 0.05), (Path. CURVE4, (2.0,-0.5), (Path. CURVE3, (3.5,-1.8), (Path. CURVE3, (2,-2), (Path. CLOSEPOLY, (1.58,-2.57),] codes, verts = zip (* path_data) path = Path (verts, codes) # drawing by commands and coordinates patch = PathPatch (path, facecolor = 'R', alpha = 0.9) ax. add_patch (patch) # Draw control polygon and connection points x, y = zip (* path. vertices) line, = ax. plot (x, y, 'go-') # displays the grid ax. grid () # Set the consistent scale of the coordinate axis to display the image ax more realistically. axis ('equal') plt. show ()

Result 2

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.