#!/usr/bin/env python # coding: utf-8 # ## Strips on sphere ## # In[1]: import numpy as np # We generate a sphere from 12 strips. The basic strip is parameterized and discretized below: # In[12]: theta=np.linspace(0, 5*np.pi/36, 30) #5pi/36=25 degrees phi=np.linspace(-np.pi/2, np.pi/2, 100) theta, phi=np.meshgrid(theta, phi) x=np.cos(theta)*np.cos(phi) y=np.sin(theta)*np.cos(phi) z=np.sin(phi) # This strip is rotated about Oz, with integer multiple of $\pi/6$ radians. Since z-rotation does not change z values, we define only a planar rotation of `alpha` radians: # In[13]: def Rot(alpha): return np.array([[np.cos(alpha), -np.sin(alpha)], [np.sin(alpha), np.cos(alpha)]]) # Instead of applying this rotation successively to each point in the basic strip, we make use of the numpy function `einsum` (Einstein summation), and rotate simultaneously all points with coordinates in two equally shaped meshgrids (x,y, in our case): # In[14]: def rotate_z_mesh(x, y, alpha): return np.einsum('ji, mni -> jmn', Rot(alpha), np.dstack([x, y])) # The colorscale to plot the sphere's strips: # In[15]: cofee_green=[[0.0,u'#543005'], [0.1,u'#8c510a'], [0.2, u'#bf812d'], [0.3, u'#dfc27d'], [0.4, u'#f6e8c3'], [0.5, u'#f5f5f5'], [0.6, u'#c7eae5'], [0.7, u'#80cdc1'], [0.8, u'#35978f'], [0.9, u'#01665e'], [1.0, u'#003c30']] # In[16]: import plotly.plotly as py import plotly.tools as tls from plotly.graph_objs import * # In[17]: def make_trace(x,y,z, colsc):# this function creates the trace for each strip on sphere return Surface( x=x, y=y, z=z, colorscale=colsc, name='' ) # In[18]: dt=[make_trace(x,y,z, cofee_green)]#initial strip for k in range(1,12): rez=rotate_z_mesh(x, y, k*np.pi/6) dt+=[make_trace(rez[0], rez[1], z, cofee_green)] # In[19]: data=Data(dt) # In[20]: axis = dict( showbackground=True, backgroundcolor='rgb(20, 20, 20)', gridcolor='rgb(75, 75, 75)', zerolinecolor='rgb(75, 75, 75)' ) layout = Layout( title='Strips on sphere', width=800, height=800, scene=Scene( xaxis=XAxis(axis), yaxis=YAxis(axis), zaxis=ZAxis(axis), ) ) fig = Figure(data=data, layout=layout) py.sign_in('empet', 'my_api_key') py.plot(fig, filename='spherical-strips') # [https://plot.ly/~empet/4759](https://plot.ly/~empet/4759) # In[31]: from IPython.core.display import HTML def css_styling(): styles = open("./custom.css", "r").read() return HTML(styles) css_styling()