A Pytri redux, using the latest available THREE.js bindings and GPU-offloaded rendering of large scenes.
WARNING: pytri is currently untested. Use at your own risk.
pip install pytri
# or:# pip3 install git+https://github.com/aplbrain/pytriLet's plot some scatterplot data in 3D. In your favorite Jupyter notebook or binder application, import pytri:
frompytriimportFigureWe can now generate some sample data:
importnumpyasnpfig=Figure()
xs=np.random.randn(100)
ys=np.random.randn(100)
zs=np.random.randn(100)
fig.scatter(xs, ys, zs)
fig.show()Here's a crazy dense randomly-arranged graph with over a million edges. (You'll find the slowest part of this process is just generating that graph!)
This graph renders in realtime (60FPS) in Pytri.
importnetworkxasnxg=nx.fast_gnp_random_graph(50_000, 0.001)
pos= {k: [vv*500forvvinv] fork, vinnx.random_layout(g, dim=3).items()}
f=Figure()
f.axes()
f.graph(g, pos=pos, edge_width=1, node_size=10)
f.show()These edges are a different color on the left edge than on the right edge:
f=Figure()
f.axes()
f.lines(
# 100 lines on the interval 0-100np.random.random((100, 2, 3)) *100,
# 200 colors, start/stop for each linecolors=np.random.random((100, 2, 3)),
width=4
)
f.show()f.imshow(
"https://i.imgur.com/VK8Tp5q.jpeg",
width=100, height=100,
rotation=(0, 3.14/2, 0)
)
f.show()f.scatter(np.random.randint(-50, 50, (1_00_000,3)))
f.imshow(
# 3 dimensions, interpreted as RGBnp.random.random((1000, 1000, 3)),
width=200, height=200,
rotation=(0, 3.14/2, 0)
)
f.imshow(
# 2 dimensions, interpreted as grayscalenp.random.random((1000, 1000)),
width=200, height=200,
# omitting rotation, the plane faces "up" along Z
)frompytriimportFigureimportinternmorgan2020=intern.array("bossdb://morgan2020/lgn/em", resolution=2)
em_excerpt=morgan2020[1000:1050, 25000:25000+300, 25000:25000+300]
coords= []
forzinrange(em_excerpt.shape[0]):
foryinrange(em_excerpt.shape[1]):
forxinrange(em_excerpt.shape[2]):
coords.append((x, y, z*10))
f=Figure()
f.scatter(coords, color=[[i,i,i] foriinem_excerpt.ravel()], attenuate_size=True, size=5)
f.show()




