Python绘制三维直方图六边形

2024-09-29 01:30:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在测试Broadcom的TOF相机。 它有六边形像素。 Representation of Broadcom pixels

我希望用3D表示直方图,就像构造器的实用程序一样

Histogram Hexa into Broadcom GUI

我测试了视频库。但我不能给出Z的值,对单元格重新排序并追踪到地面

Test of Vedo

   from vedo import *
   from vedo.pyplot import histogram
   import numpy as np

   N = 2000
   x = np.random.randn(N) * 1.0
   y = np.random.randn(N) * 1.5
   # hexagonal binned histogram:
   histo = histogram(x, y,
              bins=100,
              mode='hexbin',
              xtitle="\sigma_x =1.0",
              ytitle="\sigma_y =1.5",
              ztitle="counts",
              fill=True,
              cmap='terrain',
              )
   # add a formula:
   f = r'f(x, y)=A \exp \left(-\left(\frac{\left(x-x_{o}\right)^{2}}'
   f+= r'{2 \sigma_{x}^{2}}+\frac{\left(y-y_{o}\right)^{2}}'
   f+= r'{2 \sigma_{y}^{2}}\right)\right)'
   formula = Latex(f, c='k', s=1.5).rotateX(90).rotateZ(90).pos(1.5,-2,1)

   show(histo, formula, axes=1, viewup='z')

Tags: fromimportrightnprandomleftsigmahistogram
1条回答
网友
1楼 · 发布于 2024-09-29 01:30:44

您可以轻松地创建它,例如

from vedo import *
import numpy as np

settings.defaultFont = "Theemim"

vals = np.abs(np.random.randn(8*4)) # heights
cols = colorMap(vals, "RdYlBu")

items = []
k = 0
for i in range(8):
    for j in range(4):
        val = vals[k]
        col = cols[k]
        x, y, z = [i+j%2/2, j-j%2/6, val+0.01]
        hexa = Circle([x,y], r=0.55, res=6)
        hbar = hexa.extrude(val) # create the hex bar
        hbar.lighting("default").flat().c(col)
        txt = Text3D(precision(val,3), [x,y,z], s=.12, justify='center', c='k')
        items += [hbar, txt]
        k += 1

show(items, axes=dict(xtitle="x-cell"))

enter image description here

相关问题 更多 >