使用示例
1D点集(康托集)
import matplotlib.pyplot as plt
from FreeAeonFractal.FAVisual import CFAVisual
from FreeAeonFractal.FASample import CFASample
points_1d = CFASample.get_Cantor_Set(iterations=256)
fig, ax = plt.subplots(figsize=(10, 2))
CFAVisual.plot_1d_points(points_1d, ax=ax)
ax.set_title("康托集")
plt.show()
2D点集(谢尔宾斯基三角形)
points_2d = CFASample.get_Sierpinski_Triangle(iterations=1024)
fig, ax = plt.subplots(figsize=(6, 6))
CFAVisual.plot_2d_points(points_2d, ax=ax)
ax.set_title("谢尔宾斯基三角形")
plt.show()
3D点集(门格海绵)
points_3d = CFASample.get_Menger_Sponge(iterations=10240)
fig = plt.figure(figsize=(8, 8))
ax = fig.add_subplot(111, projection='3d')
CFAVisual.plot_3d_points(points_3d, ax=ax)
ax.set_title("门格海绵")
plt.show()
类说明(所有静态方法)
plot_1d_points(points, ax=plt)
水平散点图,Y轴隐藏。适用于康托集等1D分形。
plot_2d_points(points, ax=plt)
points:(N, 2) 坐标数组。适用于谢尔宾斯基三角形、巴恩斯利蕨等。
plot_3d_points(points, ax=None)
points:(N, 3) 坐标数组。ax=None时自动创建3D图形。适用于门格海绵等。
plot_2d_image(image, cmap='gray', ax=plt)
使用imshow显示2D图像。cmap:任意matplotlib色图。
plot_3d_image(img, ax=plt)
从(N,3)或(N,4)结构化点云显示,第4列为颜色值。
重要说明
- 所有方法接受
ax=plt(直接使用pyplot)或显式坐标轴对象 - 点数超过100K时建议先降采样
plot_3d_points需要projection='3d'坐标轴;ax=None时自动创建