import matplotlib.pyplot as plt from random_walk import Randomwalk # this script will visually plot the randomwalks # generated from the random_walk.py script # keep making new walks, as long as the program is active while True: # make random walk rw = Randomwalk(50000) # changed the num_points from default rw.fill_walk() # plot the points in the walk plt.style.use('classic') # to set it to system resolution: plt.subplots(figsize=(10, 6), dpi=128) fig, ax = plt.subplots(figsize=(10, 6), dpi=128) # set plot aspect ratio and size # color the points point_numbers = range(rw.num_points) # scatter plot uses x and y values from rw, size of plot is 15, and color parameters are inserted ax.scatter(rw.x_values, rw.y_values, c=point_numbers, cmap=plt.cm.Blues, edgecolors='none', s=5) # emphasize the first(Big Blue) and then the last(Big Red) points ax.scatter(0, 0, edgecolors='none', s=100) ax.scatter(rw.x_values[-1], rw.y_values[-1], c='red', edgecolors='none', s=100) # remove tha axes, comment out the following 2 lines if you want the # axis back ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) plt.show() # close the graph to queue the input prompt keep_running = input("Make another walk? (y/n): ")
import matplotlib.pyplot as plt from random_walk import Randomwalk rw = Randomwalk() rw.fill_walk() numwalks = list(range(rw.num_walks)) plt.scatter(rw.x_values, rw.y_values, c=numwalks, cmap=plt.cm.Blues, s=15) plt.show()
import matplotlib.pyplot as plt from random_walk import Randomwalk #只要程序处于活动状态,就不断模拟随机漫步 while True: #创建一个Randomwalk实例,并将其包含的点都绘制出来 rw = Randomwalk(50000) rw.fill_walk() #设置绘图窗口的尺寸 plt.figure(figsize=(10, 6)) point_numbers = list(range(rw.num_points)) plt.scatter(rw.x_values, rw.y_values, c=point_numbers, cmap=plt.cm.Blues, edgecolors='none', s=1) #突出起点和终点 plt.scatter(0, 0, c='green', edgecolors='none', s=100) plt.scatter(rw.x_values[-1], rw.y_values[-1], c='red', edgecolors='none', s=100) #隐藏坐标轴 plt.axes().get_xaxis().set_visible(False)
import matplotlib.pyplot as plt from pylab import * mpl.rcParams['font.sans-serif'] = ['SimHei'] from random_walk import Randomwalk #随机游走循环 while True: #创建一个随机游走用例,并随机游走 randomwalk=Randomwalk(50000) randomwalk.walk() #设置绘制窗口 plt.figure(dpi=128,figsize=(100,60)) #绘制图像 point_numbers=list(range(randomwalk.num_points+1)) plt.scatter(randomwalk.x_values,randomwalk.y_values, c=point_numbers,cmap=plt.cm.Blues,edgecolors='none',s=1) #重新绘制起点和终点 plt.scatter(0,0,c='green',edgecolors='none',s=100) plt.scatter(randomwalk.x_values[-1],randomwalk.y_values[-1], c='green',edgecolors='none',s=100) #隐藏坐标轴 plt.axes().get_xaxis().set_visible(False) plt.axes().get_yaxis().set_visible(False) #显示图像 plt.show() keep_running=input('你愿意继续吗,请按y/n') if keep_running=='n': break