Python绘制牛奶冻曲线(高木曲线)案例
作者:微小冷 时间:2022-04-05 16:35:08
前言:
牛奶冻曲线(blancmange curve),因在1901年由高木贞治所研究,又称高木曲线。
在单位区间内,牛奶冻函数定义为:
分形曲线的轮廓会随着阶数的增多而填充细节,即对于下面的来说, N的变化会增添曲线的自相似特性
import numpy as np
import matplotlib.pyplot as plt
s = lambda x : np.min([x-np.floor(x), np.ceil(x)-x],0)
x = np.arange(1000).reshape(-1,1)/1000
N = np.arange(30).reshape(1,-1) #2^N已经很大了,精度足够
b = np.sum(s(2**N*x)/2**N,1)
plt.plot(b)
plt.show()
如图所示:
牛奶冻曲线是一种典型的分形曲线,即随着区间的不断缩小,其形状几乎不发生什么变化,例如更改自变量的范围,令
x = np.arange(0.25,0.5,1e-3).reshape(-1,1)
最终得到的牛奶冻曲线在观感上是没什么区别的。
接下来绘制一下,当区间发生变化时,牛奶冻曲线的变化过程
绘图代码为:
from aniDraw import *
# 三角波函数
s = lambda x : min(np.ceil(x)-x, x-np.floor(x))
s = lambda x : np.min([x-np.floor(x), np.ceil(x)-x],0)
x = np.arange(1000).reshape(-1,1)/1000
N = np.arange(30).reshape(1,-1) #2^N已经很大了,精度足够
b = np.sum(s(2**N*x)/2**N,1)
fig = plt.figure(figsize=(12,8))
ax = fig.add_subplot()
# n为坐标轴参数
def bcFunc(n):
st = 1/3 - (1/3)**n
ed = 1/3 + (2/3)**n
x = np.linspace(st,ed,1000).reshape(-1,1)
b = np.sum(s(2**N*x)/2**N,1)
return (x,b)
line, = ax.plot([],[],lw=1)
def animate(n):
x,y = bcFunc(n)
line.set_data(x,y)
plt.xlim(x[0],x[-1])
plt.ylim(np.min(y),np.max(y))
return line,
Ns = np.arange(1,10,0.1)
ani = animation.FuncAnimation(fig, animate, Ns,
interval=125, blit=False)
plt.show()
来源:https://blog.csdn.net/m0_37816922/article/details/126517261
标签:Python,绘制,曲线
0
投稿
猜你喜欢
Python字典推导式将cookie字符串转化为字典解析
2023-02-26 14:22:17
Python实现学生成绩管理系统
2023-08-13 09:51:17
判断python字典中key是否存在的两种方法
2023-08-19 00:18:05
区别div和span、relative和absolute、display和visibility
2009-12-13 12:18:00
golang语言map全方位介绍
2024-05-22 10:20:33
python机器学习之神经网络
2023-11-10 21:39:19
反向传播BP学习算法Gradient Descent的推导过程
2022-09-08 09:51:06
Python fileinput模块使用介绍
2023-08-22 14:32:12
Go Generate 代替 Makefile使用方法详解
2024-04-27 15:28:18
C# Ado.net实现读取SQLServer数据库存储过程列表及参数信息示例
2024-01-12 20:16:06
vue-cli使用stimulsoft.reports.js的详细教程
2024-04-09 10:58:59
Pytho的HTTP交互httpx包模块使用详解
2022-11-17 06:03:29
python2和python3实现在图片上加汉字的方法
2021-08-16 05:46:29
MSSQL 检查所使用的语句是否符合标准
2024-01-26 00:42:40
五个基于JS实现的炫酷登录页面
2024-04-17 09:43:25
python可视化hdf5文件的操作
2022-11-16 16:35:48
详细讲解MySQL数据库对文件操作的封装
2008-12-17 16:08:00
对Keras中predict()方法和predict_classes()方法的区别说明
2022-11-05 09:13:32
python 爬取疫情数据的源码
2022-05-22 13:21:54
python读取csv和txt数据转换成向量的实例
2021-09-12 12:01:24