像素直方图。

pixhist的Python项目详细描述


皮克斯主义者

pip install pixhist

pixlist-像素直方图。

依赖项:NumbaNumPy,和{a4}来使用pixhist.rendering。在

importmatplotlib.pyplotaspltfromnumbaimportnjitimportnumpyasnpimportpixhistimportpixhist.rendering

示例1:从生成器创建pixlist

生成器应该没有参数,并返回值x, y

generator() -> x, y

它应该用Numba的njit/jit编译。在

^{pr2}$

png

示例2:使用发电机工厂

创建一个'generator factory'来避免生成器应该没有参数这一事实。在

defget_clifford_generator(a,b,c,d,x_i=0,y_i=0):@njitdefgen():x,y=x_i,y_iwhileTrue:yieldx,yx_=np.sin(a*y)+c*np.cos(a*x)y_=np.sin(b*x)+d*np.cos(b*y)x,y=x_,y_returngenparams=[1.8,-1.4,-1.5,-0.71]gen=get_clifford_generator(*params)r=pixhist.estimate_range(gen,n_iter=100_000)N_ITER=1000_000W,H=500,500hist=pixhist.from_gen(gen,N_ITER,W,H,range=r,make_xy_proportional=False,log=True)pixhist.rendering.plot(hist,cmap='twilight')plt.show()

png

示例3:数组中的pixlist

从两个长度相同的数组创建一个像素直方图。在

x_vals=np.random.random(100_000)y_vals=np.sin(x_vals)**2*np.random.random(100_000)W,H=200,300hist=pixhist.from_arrays(x_vals,y_vals,W,H,make_xy_proportional=True,log=True)pixhist.rendering.plot(hist,cmap='nipy_spectral')plt.show()

png

例4:使用发电机的好处

由于不需要将数组x_vals, y_vals存储在内存中,所以可以有大量的迭代。(时间成为限制因素)。在

frommagic_timerimportMagicTimerparams=[1.8,-1.4,-1.5,-0.71]gen=get_clifford_generator(*params)r=pixhist.estimate_range(gen,n_iter=100_000)N_ITER=100_000_000W,H=500,500t=MagicTimer()hist=pixhist.from_gen(gen,N_ITER,W,H,range=r,make_xy_proportional=False,log=True)print('Time elapsed:',t)pixhist.rendering.plot(hist,cmap='twilight')plt.show()
Time elapsed: 8.4 seconds

png

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
带有服务类安卓的java altbeacon   java在OpenXava免费版本中可以创建多个用户吗?   java如何决定定义变量“private”?   java为什么GetMethodID()对不存在的方法不返回NULL?   java Get JComboBox项字符串表示法   java如何在ifs之间设置限制?   java Android错误:IllegalStateException   JavaSpring4MVC语言环境已更改,但JSP对此没有响应   java Netbeans:如何构建。jar文件随附外部文件。jar库?   Spring Petclinic项目Maven编译时出现java错误   声明Java数组增量元素的快速方法   java无法使用相对xpath找到元素   javascript无法更改标题,也无法在操作栏上显示图标   java标签不是一个接一个地动态创建的   java如何使用ThymeLeaf将对象的属性绑定到隐藏字段?   java从EJB无状态会话bean调用CDI会话范围的生产者方法   java为什么num+=array[i]与for循环中的num=num+array[i]的工作方式不同   使用jsonsimple实现jQuery UI自动完成的java JSON格式   JavaFaceletsUI:重复标记中断JSF表单验证