gll89的个人博客分享 http://blog.sciencenet.cn/u/gll89

博文

使用plotly在线显示3D可交互图像

已有 3991 次阅读 2019-8-29 15:28 |个人分类:Python|系统分类:科研笔记

安装软件

    plotly包、jupyter notebook

使用方法

为了在线显示,

1)在plotly官网进行注册

2)在“setting”页面,点击“Regenerate Key”生成API-Key

api-key.PNG

3)在代码中增加如下两行代码:

    import plotly

    plotly.tools.set_credentials_file(username='your-name', api_key='your-API-Key')

生成的图像可在网站“My Files”中查看

实例

如下代码为Jupyter notebook中的一个例子:


import numpy as np

from skimage import measure

import matplotlib.pyplot as plt

import plotly

import plotly.plotly as py

from plotly import figure_factory as FF

plotly.tools.set_credentials_file(username='***', api_key='***')


def pltly_3d(image, filename=None, th=100, step_size=1):

    #Transposing & Calculating surface

    print('Making mesh...')

    p = image.transpose(2,1,0)

    verts, faces, norm, val = measure.marching_cubes_lewiner(p, th, step_size=2, allow_degenerate=True)


    print ("Drawing...")

    x,y,z = zip(*verts)

     

    # Fancy indexing: `verts[faces]` to generate a collection of triangles

    colormap=['rgb(236, 236, 212)','rgb(236, 236, 212)']


    fig = FF.create_trisurf(x=x,y=y,z=z,

                        colormap=colormap,

                        simplices=faces,

                        backgroundcolor='rgb(64, 64, 64)',

                        title="Interactive Visualization")

    py.iplot(fig,filename=filename)



npy_path = 'H:\\2019-8-11\\dealed\\test\\rm_bg.npy'

rm_bg = np.load(npy_path)

print(rm_bg.shape)

filename = 'rm_bg'

pltly_3d(rm_bg,filename=filename, th=2)



references:

https://computational-communication.com/plotly/

https://plot.ly/python/v3/trisurf/

https://plot.ly/python/



https://blog.sciencenet.cn/blog-1969089-1195761.html

上一篇:[转载]several blocks of Deep learning
下一篇:attention-based papers accepted by MICCAI 19

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2022-1-29 07:26

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部