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