对python应用的一个巩固,以及熟悉matplotlib的用法

效果如下:

# -*- coding: utf-8 -*-
"""
Created on Fri Sep 28 22:39:55 2018
@author: pprp
""" from random import choice
import matplotlib.pyplot as plt class RandomWalk():
"""a class using to generate random data"""
def __init__(self,num_points=5000):
"""init the class"""
self.num_points=num_points # start at (0,0)
self.x_val=[0]
self.y_val=[0] def fill_walk(self):
"""calculate the points"""
while len(self.x_val) < self.num_points:
x_direction=choice([1,-1])
x_distance=choice([0,1,2,3,4,5])
x_step = x_direction * x_distance y_direction=choice([1,-1])
y_distance=choice([1,2,5,4,0])
y_step = y_direction * y_distance if x_step == 0 and y_step == 0:
continue
next_x = self.x_val[-1]+x_step
next_y = self.y_val[-1]+y_step self.x_val.append(next_x)
self.y_val.append(next_y) rw = RandomWalk(50000)
rw.fill_walk() plt.tick_params(axis='both',labelsize=14) point_nums=list(range(rw.num_points))
plt.scatter(rw.x_val,rw.y_val,s=1,c=point_nums,cmap=plt.cm.Blues,edgecolors='none') # plot the start point and end point
plt.scatter(0,0,c='green',edgecolors='none',s=100)
plt.scatter(rw.x_val[-1],rw.y_val[-1],c='red',edgecolors='none',s=100) # set figure width and height
plt.figure(dpi=1280,figsize=(10,6))
plt.show()

最新文章

  1. 统计代码git提交的行数
  2. Otsu algorithm
  3. [已解决] java.net.InetAddress.getHostName() 阻塞问题
  4. springmore-让编程更容易
  5. 高效PHP开发注意事项
  6. Android 进度条
  7. ImageOptim 图片压缩工具
  8. php访问类静态属性
  9. NOIP2014酱油记
  10. 原创+部分引用啦:C# Winform界面中的分隔线问题
  11. Android 新兴的UI模式——侧边导航栏【转】
  12. jmeter命令行运行-单节点
  13. 基于react全家桶+antd-design+webpack2+node+express+mongodb开发的前后台博客系统
  14. vue.js购物车
  15. Nodejs之路:非I/O的异步API
  16. loadrunner&#160;脚本优化-关联设置
  17. aop 记录用户操作(一)
  18. 在 Laravel 5.1 中使用 Pjax
  19. ReactJS表单handleChange
  20. sed 以及 awk用法

热门文章

  1. my sql 两个 索引 时的 union 与 or 的比较
  2. js的字符串charAt()方法
  3. EUI组件之HScrollBar VScrollBar (动态设置滑块图片)
  4. 170622、springboot编程之JPA操作数据库
  5. Asp.net读取和写入txt文件方法(实例)!
  6. Process Monitor分析某个应用行为
  7. talib 中文文档(十一):Cycle Indicator Functions 周期指标
  8. 005-spring cache-配置缓存存储
  9. HDFS的工作流程分析
  10. /etc/rc.d/rc.local linux启动自动开启某些服务(转)