import matplotlib.pyplot as plt from random import choice class RandomStep(): def __init__(self,num_steps=5000): self.steps = num_steps self.x_points = [0] self.y_points = [0] def fill_points(self): while (len(self.x_points) < self.steps): x_dir = choice([-1,1]) #设置随机漫步的方向 x_dit = choice([0,1,2
Python3实现简单的随机漫步散点图
最新推荐文章于 2021-09-23 18:06:58 发布
本文展示了如何使用Python3实现一个简单的随机漫步散点图。通过创建`RandomStep`类,设定随机漫步的方向和距离,最终利用matplotlib库绘制出具有起点和终点的蓝色渐变散点图。用户可以选择是否生成随机漫步图并保存为PNG文件。
摘要由CSDN通过智能技术生成