使用Mayavi的Jupyter Notebook中的地球纹理球体

时间:2019-02-21 20:41:14

标签: python jupyter-notebook mayavi

在Jupyter笔记本中,我正在尝试实现以下答案中提供的算法:

Map an image onto a sphere and plot 3D trajectories

它在独立的python文件中效果很好,但是当我在笔记本中提供相同的实现时,最终只能得到黑色球体,而不是纹理球体。下面是我在笔记本中使用的单元格:

from mayavi import mlab
mlab.init_notebook(local=True)
from tvtk.api import tvtk
import numpy as np

img = tvtk.JPEGReader()
img.file_name = "blue_marble.jpg"
# map the texture
texture = tvtk.Texture(input_connection=img.output_port, interpolate=0)

# make the sphere
R = 1
Nrad = 180

# create the sphere
sphere = tvtk.TexturedSphereSource(radius=R, theta_resolution=Nrad,  
  phi_resolution=Nrad)
#assembly required
sphere_mapper = tvtk.PolyDataMapper(input_connection=sphere.output_port)
sphere_actor = tvtk.Actor(mapper=sphere_mapper, texture=texture)
# plot
mlab.clf()
fig = mlab.figure(size=(800, 600), bgcolor=(1,1,1))
fig.scene.add_actor(sphere_actor)
fig

谢谢!

0 个答案:

没有答案