W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
# 这三行代码使编译器能够绘图: import sys import matplotlib matplotlib.use('Agg') import numpy as np import matplotlib.pyplot as plt # 准备运动数据(心率和卡路里): x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125]) y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330]) # 设置图表标题和坐标轴标签: plt.title("运动手表数据") # 图表主标题 plt.xlabel("平均脉搏") # x 轴标签 plt.ylabel("卡路里消耗") # y 轴标签 # 绘制脉搏与卡路里关系曲线: plt.plot(x, y) # 添加绿色虚线网格: plt.grid(color = 'green', linestyle = '--', linewidth = 0.5) plt.show() # 这两行代码使编译器能够输出图形: plt.savefig(sys.stdout.buffer) sys.stdout.flush()