Python 代码绘制康托三分集图形
以下是一个简单的 Python 代码,用于绘制康托三分集:
import matplotlib.pyplot as plt
def cantor_set(x1, x2, y, depth):
'递归绘制康托三分集'
if depth == 0:
plt.plot([x1, x2], [y, y], 'k')
else:
dx = (x2 - x1) / 3
cantor_set(x1, x1 + dx, y - 1, depth - 1)
cantor_set(x2 - dx, x2, y - 1, depth - 1)
# 绘制康托三分集
plt.figure(figsize=(8, 4))
cantor_set(0, 1, 0, 5)
plt.axis('off')
plt.show()
该代码会生成一个康托三分集的图形。您可以根据需要调整参数来控制图形的大小和深度。
原文地址: https://www.cveoy.top/t/topic/oRgb 著作权归作者所有。请勿转载和采集!