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