# Adding wireframe around a sphere

**URL:** <https://community.plotly.com/t/adding-wireframe-around-a-sphere/37661>\
**Category:** 📊 Plotly Python\
**Created:** [April 12, 2020, 5:00pm UTC](https://community.plotly.com/t/adding-wireframe-around-a-sphere/37661 "2020-04-12T17:00:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![avivazran](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@avivazran](https://community.plotly.com/u/avivazran)\
**Post date:** [April 12, 2020, 5:00pm UTC](https://community.plotly.com/t/adding-wireframe-around-a-sphere/37661/1 "2020-04-12T17:00:24Z")

</div>

I have the following code,

```auto
    def plot_back(self):
        """back half of sphere"""
        u_angle = np.linspace(0, np.pi, 25)
        v_angle = np.linspace(0, np.pi, 25)
        x_dir = np.outer(np.cos(u_angle), np.sin(v_angle))
        y_dir = np.outer(np.sin(u_angle), np.sin(v_angle))
        z_dir = np.outer(np.ones(u_angle.shape[0]), np.cos(v_angle))
        self.plotly_figure.add_surface(z=z_dir, x=x_dir, y=y_dir, opacity=self.sphere_alpha,
                                       colorscale=[[0, self.sphere_color], [1, self.sphere_color]])

        # wireframe
        lines = []
        line_marker = dict(color=self.frame_color, width=2)
        for i, j, k in zip(x_dir[0::5], y_dir[0::5], z_dir[0::5]):
            lines.append(go.Scatter3d(x=i, y=j, z=k, mode='lines', line=line_marker, opacity=self.frame_alpha))
        self.plotly_figure.add_traces(lines)

 def plot_front(self):
        """front half of sphere"""
        u_angle = np.linspace(-np.pi, 0, 25)
        v_angle = np.linspace(0, np.pi, 25)
        x_dir = np.outer(np.cos(u_angle), np.sin(v_angle))
        y_dir = np.outer(np.sin(u_angle), np.sin(v_angle))
        z_dir = np.outer(np.ones(u_angle.shape[0]), np.cos(v_angle))
        self.plotly_figure.add_surface(z=z_dir, x=x_dir, y=y_dir, opacity=self.sphere_alpha,
                                       colorscale=[[0, self.sphere_color], [1, self.sphere_color]])
        # wireframe
        lines = []
        line_marker = dict(color=self.frame_color, width=2)
        for i, j, k in zip(x_dir[0::5], y_dir[0::5], z_dir[0::5]):
            lines.append(go.Scatter3d(x=i, y=j, z=k, mode='lines', line=line_marker, opacity=self.frame_alpha))

```

which produces a sphere as show below:  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/5/538fc21051d22c70448b3a61fe13fff600820d3f.png)

I want to add circles around the sphere so it will end up looking something like this:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/e/efaed2ad7368b7e18b0140d76fdf7c3c148efe5b.png)  
but i can’t seem to get this right and i;ve been trying for hours now.

HELP!

thanks

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [April 13, 2020, 11:46am UTC](https://community.plotly.com/t/adding-wireframe-around-a-sphere/37661/2 "2020-04-13T11:46:22Z")

</div>

Hi @avivazran,

I’m wondering why are you defining the sphere from two semi-spheres, because it is possible to define the whole surface at once. Here is the code to plot both the sphere and a number of meridians and parallels:

```auto
import numpy as np
import plotly.graph_objs as go
from numpy import pi, sin, cos

theta = np.linspace(0, 2*pi, 120)
phi = np.linspace(0, pi, 60)
u , v = np.meshgrid(theta, phi)
xs = cos(u)*sin(v)
ys = sin(u)*sin(v)
zs = cos(v)

x = []
y = []
z = []
for t in [theta[10*k] for k in range(12)]: # meridians:
    x.extend(list(cos(t)*sin(phi))+[None])# None is inserted to mark the end of a meridian line
    y.extend(list(sin(t)*sin(phi))+[None]) 
    z.extend(list(cos(phi))+[None])
    
for s in [phi[6*k] for k in range(10)]: # parallels
    x.extend(list(cos(theta)*sin(s))+[None]) # None is inserted to mark the end of a parallel line 
    y.extend(list(sin(theta)*sin(s))+[None]) 
    z.extend([cos(s)]*120+[None])

fig=go.Figure()
fig.add_surface(x=xs, y=ys, z=zs, 
                colorscale=[[0, '#ffffff'], [1, '#ffffff']], 
                showscale=False, opacity=0.5) # or opacity=1
fig.add_scatter3d(x=x, y=y, z=z, mode='lines', line_width=3, line_color='rgb(10,10,10)')
fig.update_layout(width=700, height=700)

```
