0

In a Jupyter notebook I am trying to implement the algorithm, provided in the answer below:

Map an image onto a sphere and plot 3D trajectories

It works great in a stand alone python file but when I provide the same implementation in a notebook I end up with only a black sphere instead of textured sphere. Below is the cell I use in the notebook:

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

Thanks!

0 Answers0