rw_visual

import matplotlib.pyplot as plt
from random_walk import RandomWalk

# 创建一个RandWalk实例,并将其包含的所有点都绘制出来
rw = RandomWalk()
rw.fill_walk()
plt.scatter(rw.x_values,rw.y_values,c = rw.y_values,cmap=plt.cm.Blues,edgecolors="none",s=15)
plt.show()


while True:
    rw = RandomWalk()
    rw.fill_walk()
    plt.scatter(rw.x_values, rw.y_values, c=rw.y_values, cmap=plt.cm.Blues, edgecolors="none", s=15)
    plt.show()

    keep_running = input("Make another walk?(y/n): ")
    if keep_running == "n":
        break


"""给点着色"""
while True:
    rw = RandomWalk()
    rw.fill_walk()

    point_numbers = list(range(rw.num_points))
    # 使用颜色映射来指出漫步中各点的先后顺序,并删除黑色轮廓y
    plt.scatter(rw.x_values,rw.y_values,c=point_numbers,cmap=plt.cm.Blues,edgecolors="none",s=15)
    plt.show()

    keep_running = input("Make another walk?(y/n): ")
    if keep_running == "n":
        break

"""重新绘制起点和终点"""
while True:
    rw = RandomWalk()
    rw.fill_walk()

    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=15)

    # 突出起点和终点
    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.show()

    keep_running = input("Make another walk?(y/n): ")
    if keep_running == "n":
        break

"""隐藏坐标轴"""
while True:
    rw = RandomWalk()
    rw.fill_walk()

    plt.scatter(rw.x_values,rw.y_values,c="red",edgecolors="none",s=100)
    
    # 修改坐标轴的显示属性为False
    plt.axes().get_xaxis().set_visible(False)
    plt.axes().get_yaxis().set_visible(False)

    plt.show()

    keep_running = input("Make another walk?(y/n): ")
    if keep_running == "n":
        break

"""增加点数"""
# 增加num_points为50000,提供更多的数据
rw = RandomWalk(50000)
rw.fill_walk()

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=10)
plt.scatter(rw.x_values[-1],rw.y_values[-1],c="red",edgecolors="none",s=10)
plt.show()


"""调整尺寸以适应屏幕"""
rw = RandomWalk()
rw.fill_walk()

# figure()函数用于指定图表的宽度,高度,分辨率和背景色
# 给 figsize 指定一个元组,表示绘图窗口的尺寸,单位为英寸
# dpi指示分辨率,如 plt.figure(dpi=128,figsize=(10,6))
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.show()

猜你喜欢

转载自blog.csdn.net/wyzworld/article/details/88245045