"Python" Scientific Computing Special _ Scientific Drawing library Matplotlib Learning

Source: Internet
Author: User

Thought: All things are objects

Homework

First question:

Import NumPy as Npimport matplotlib.pyplot as Pltx = [1, 2, 3, 1]y = [1, 3, 0, 1]def plot_picture (x, y):    plt.plot (x, y , color= ' R ', linewidth= ' 2 ', linestyle= '--', marker= ' D ', label= ' one ')    plt.xticks (list (range ( -5,5,1)))    Plt.yticks (list (range ( -5,5,1)))    Plt.grid(True)    def rotate (x0, y0, point=[0, 0], ANGLE=NP.PI/2):    rx = []    ry = []    for I, POS in enumerate (Zip (x0,y0)):        rx.append ((x0[i]-point[0)) * Np.cos (angle)-(y0[i]-point[1]) *np.sin (angle) + point[0])        ry.append ((y0[i]-point[1)) *np.cos (angle) + (x0[i]- Point[0]) *np.sin (angle) + point[1])    return rx, Ryprint (rotate ([3,1],[0,1],angle=-np.pi/2)) plot_picture (x, y) Plot_picture (rotate (x, y, ANGLE=-NP.PI/2) [0], rotate (x, y, ANGLE=-NP.PI/2) [1])

The second question:

% matplotlib inlineimport NumPy as Npimport matplotlib.pyplot as Pltfig = Plt.figure () fig.add_subplot (321) fig.add_ Subplot (322) Fig.add_subplot (312) fig.add_subplot (325) Fig.add_subplot (326) fig.subplots_adjust (hspace=0.3)

Question three:

def rotate (x0, y0, point=[0, 0], ANGLE=NP.PI/2):    rx = []    ry = []    for I, POS in enumerate (Zip (x0,y0)):        rx.a Ppend ((x0[i]-point[0]) *np.cos (angle)-(y0[i]-point[1]) *np.sin (angle) + point[0])        ry.append ((y0[i]-point[1)) * Np.cos (angle) + (x0[i]-point[0]) *np.sin (angle) + point[1])    return rx, Rydef draw_flower (step=4, start_point=[2,0]) :    step = 2**step    start_x = [start_point[0]]    start_y = [Start_point[1]]    x = []    y = []    b_x = []
   b_y = []    for I in Range (step):        angle = (STEP/4) *2*np.pi/(step-1)        start_x, start_y = Rotate (start_x, STA Rt_y, Angle=angle)        x + = start_x        y + = start_y        if I! = 0:            b_x.append ((x[-2]+start_x)/2)            b_ Y.append ((y[-2]+start_y)/2)    plt.plot (x, Y, ' R ')    Plt.plot (b_x, b_y, ' B. ') Plt.axis (' equal ')    Plt.grid ( True) Draw_flower (6)

Required chrysanthemum diagram, hole a bit large, adjust angle can be resized,

The third question needs a little analytic geometry computation, the difficulty is not big, mainly is the recollection geometry knowledge to compare the pain, obviously just has tested, eh.

"Python" Scientific Computing Special _ Scientific Drawing library Matplotlib Learning

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.