BPlan-Wiki Wiki
Brought to you by:
yuanhy0055
print("Hello!, env Py3!");
import matplotlib.pyplot as plt
import numpy as np
import random
import math
x = []
y = []
# 生成一个0到1之间的随机浮点数
for i in range(1000):
random_org = random.random()
random_number = math.floor(random_org * 10)
x.append(i)
if((i+1)%200 == 0):
y.append(150+random_number)
#print(150+random_number)
else:
y.append(100+random_number)
#print(100+random_number)
# Open a file in write mode
try:
with open("Mydata.txt", "w") as file:
for item in y:
file.write(f"{item}\n")
except FileExistsError:
print("File already exists.")
plt.ylim(-10, 200)
plt.plot(x, y, label='MyData')
# plt.scatter(x, y)
# 设置标题和标签
plt.title("My Functions")
plt.xlabel("x")
plt.ylabel("y")
plt.legend() # 显示图例
# 获取当前图像的图像管理器
manager = plt.get_current_fig_manager()
# 切换全屏显示
manager.full_screen_toggle()
# 展示图像
plt.show()