W3School TIY Editor

  • W3School 在线教程
  • 改变方向
  • 暗黑模式
​x
 
# 三行配置使编译器支持绘图功能:
import sys
import matplotlib
matplotlib.use('Agg')
​
import numpy as np
from scipy.spatial import Delaunay
import matplotlib.pyplot as plt
​
# 定义二维点集:
points = np.array([
  [2, 4],  # 点 1 坐标
  [3, 4],  # 点 2 坐标
  [3, 0],  # 点 3 坐标
  [2, 2],  # 点 4 坐标
  [4, 1]   # 点 5 坐标
])
​
# 计算 Delaunay 三角剖分:
simplices = Delaunay(points).simplices
​
# 绘制三角网格和散点图:
plt.triplot(points[:, 0], points[:, 1], simplices)  # 绘制三角剖分
plt.scatter(points[:, 0], points[:, 1], color='r')   # 绘制红色散点
​
plt.show()
​
# 两行代码实现图形输出:
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()