||
plotly包、jupyter notebook
为了在线显示,
1)在plotly官网进行注册
2)在“setting”页面,点击“Regenerate Key”生成API-Key
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/
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-23 07:22
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社