W3School TIY Editor

  • W3School 在线教程
  • 改变方向
  • 暗黑模式
​x
 
# 这三行代码使编译器能够绘图:
import sys
import matplotlib
matplotlib.use('Agg')
​
import matplotlib.pyplot as plt
import numpy as np
​
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])
​
plt.subplot(2, 3, 1)  # 创建 2 行 3 列的第 1 个子图
plt.plot(x,y)
​
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])
​
plt.subplot(2, 3, 2)  # 创建 2 行 3 列的第 2 个子图
plt.plot(x,y)
​
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])
​
plt.subplot(2, 3, 3)  # 创建 2 行 3 列的第 3 个子图
plt.plot(x,y)
​
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])
​
plt.subplot(2, 3, 4)  # 创建 2 行 3 列的第 4 个子图
plt.plot(x,y)
​
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])
​
plt.subplot(2, 3, 5)  # 创建 2 行 3 列的第 5 个子图
plt.plot(x,y)
​
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])
​
plt.subplot(2, 3, 6)  # 创建 2 行 3 列的第 6 个子图
plt.plot(x,y)
​
plt.show()
​
# 这两行代码使编译器能够输出图形:
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()