Getting Started with Python drawing

Source: Internet
Author: User

Getting Started with Python drawing

Studied: https://zhuanlan.zhihu.com/p/34200452

Api:https://matplotlib.org/api/pyplot_api.html

plot.py:

#Import the module as take aliasImportMatplotlib.pyplot as PltImportMatplotlib as mplmpl.rcparams["Font.sans-serif"] = ["Youyuan"]#Data List#X-Axis#input_values = [1,2,3,4,5]Input_values = List (range (1024))#Y-Axis#squares = [1,4,9,16,25]Squares = [A * * 2 forAinchInput_values]#Draw a graphic#plt.plot (input_values, squares)Plt.scatter (Input_values, Squares,c=squares, cmap=plt.cm.Blues)#set Title, Axis plus labelPlt.title ("Chinese Square number", fontsize=24)#Plt.xlabel (' Value ', fontsize=14)#Plt.ylabel (' Square of Value ', fontsize=14)#set the size of the scale#Plt.tick_params (axis= ' both ', labelsize=14)#Show ItPlt.show ()

randomwalk.py:

 fromRandomImportChoiceclassRandomwalk:def __init__(Self, num_points=500):        " "Initialize Parameters" "self.num_points=num_points#Initial PositionSelf.x_values =[0] self.y_values=[0]defFill_walk (self):" "calculate the position of a bit" "         whileLen (self.x_values) <self.num_points:#To determine the direction and the forward distancex_direction = Choice ([-1, 1]) x_distance= Choice ([0, 1, 2, 3, 4]) X_step= X_direction *x_distance y_direction= Choice ([-1, 1]) y_distance= Choice ([0, 1, 2, 3, 4]) Y_step= Y_direction *y_distance#refusing to tread            ifX_step = = 0 andY_step = =0:Continue            #calculate the next pointnext_x = Self.x_values[-1] +X_step next_y= Self.y_values[-1] +Y_step#Append to Listself.x_values.append (next_x) self.y_values.append (next_y)

777.py:

Import Matplotlib.pyplot as Plt  from Import Randomwalk # Instantiate class RW = Randomwalk (rw.fill_walk= list (range))#  plt.plot (rw.x_ values,rw.y_values)plt.scatter (rw.x_values,rw.y_values, s=15,c=points_numbers,cmap=plt.cm.Blues) Plt.show ()

Getting Started with Python drawing

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.