This notebook illustrates some plotting capabilities of manifold objects in SageMath.
More examples can be found on the SageManifolds page.
%display latex
Let us consider the sphere $\mathbb{S}^2$. In SageMath, we declare it as a 2-dimensional differentiable manifold:
S2 = Manifold(2, 'S^2', latex_name=r'\mathbb{S}^2', start_index=1)
print(S2)
2-dimensional differentiable manifold S^2
We then introduce the standard spherical coordinates $(\theta,\phi)$ as a chart on $\mathbb{S}^2$, denoting the chart as spher
and the coordinates th
and ph
.
We shall be lazy here and consider that the spherical chart covers the whole manifold $\mathbb{S}^2$; this amounts to authorize coordinate singularities:
spher.<th,ph> = S2.chart(r'th:[0,pi]:\theta ph:[0,2*pi]:periodic:\phi')
spher
spher.coord_range()
For 3D plots, we shall require the Euclidian space $\mathbb{E}^3$:
E3.<X,Y,Z> = EuclideanSpace()
E3
Let us call cartesian
the chart of Cartesian coordinates $(X,Y,Z)$:
cartesian = E3.cartesian_coordinates()
cartesian
The canonical embedding of $\mathbb{S}^2$ into $\mathbb{E}^3$:
Phi = S2.diff_map(E3, (sin(th)*cos(ph),
sin(th)*sin(ph),
cos(th)),
name='Phi', latex_name=r'\Phi')
Phi.display()
Each chart is endowed with a plot()
method.
For instance, we may use it to plot the chart of spherical coordinates plotted in terms
of itself:
spher.plot(chart=spher)
More intersting is to the plot the chart of spherical coordinates in terms of $\mathbb{E}^3$'s Cartesian coordinates, via the embedding $\Phi:\; \mathbb{S}^2\to\mathbb{E}^3$:
spher.plot(chart=cartesian, mapping=Phi)
For a better image, let us increase the number of coordinate values:
spher.plot(chart=cartesian, mapping=Phi, number_values=11)
One can customize the color of coordinate lines:
spher.plot(chart=cartesian, mapping=Phi, number_values=11,
color={th: 'red', ph: 'green'})
One can fix the value of some coordinates, thereby obtaining a partial plot:
spher.plot(chart=cartesian, mapping=Phi, number_values=11,
color={th: 'red', ph: 'green'},
fixed_coords={th: pi/4})
or limit the range of some coordinates:
spher.plot(chart=cartesian, mapping=Phi, number_values=11,
color={th: 'red', ph: 'green'},
ranges={ph:(0, pi)})
One can also restrict the coordinates of the ambiant chart; here is a example of plot of the chart spher
in terms of the coordinates $(X,Y)$ of $\mathbb{E}^3$:
spher.plot(chart=cartesian, mapping=Phi, number_values=11,
color={th: 'red', ph: 'green'},
ambient_coords=(X, Y))
Same thing with only the coordinates $(X,Z)$:
spher.plot(chart=cartesian, mapping=Phi, number_values=11,
color={th: 'red', ph: 'green'},
ambient_coords=(X, Z))
Let us introduce the chart of stereographic coordinates from the North pole:
stereoN.<x,y> = S2.chart()
stereoN
spher_to_stereoN = spher.transition_map(stereoN,
(sin(th)*cos(ph)/(1-cos(th)),
sin(th)*sin(ph)/(1-cos(th))))
spher_to_stereoN.display()
spher_to_stereoN.set_inverse(2*atan(1/sqrt(x^2+y^2)), atan2(-y,-x)+pi)
Check of the inverse coordinate transformation: th == 2*arctan(sqrt(-cos(th) + 1)/sqrt(cos(th) + 1)) **failed** ph == pi + arctan2(sin(ph)*sin(th)/(cos(th) - 1), cos(ph)*sin(th)/(cos(th) - 1)) **failed** x == x *passed* y == y *passed* NB: a failed report can reflect a mere lack of simplification.
Plot of spherical coordinate in terms of the stereographic ones:
spher.plot(chart=stereoN, number_values=15, ranges={th: (pi/8,pi)},
color={th: 'red', ph: 'green'})
Plot of stereographic coordinates in terms of spherical ones:
stereoN.plot(chart=spher, number_values=15, plot_points=200,
color={x: 'blue', y: 'orange'})
The expression of the embedding $\Phi$ in terms of the stereographic coordinates is computed by Sage:
Phi.display()
This means that we can use $\Phi$ for a 3D view of the stereographic chart:
stereoN.plot(chart=cartesian, mapping=Phi, number_values=25,
color={x: 'blue', y: 'orange'})
The hole at the North pole is due to the default limitation to $[-8,8]$ for the plot range of coordinates that span the whole real line. We can change it to $[-20, 20]$ via the argument max_range
:
stereoN.plot(chart=cartesian, mapping=Phi, number_values=25,
color={x: 'blue', y: 'orange'},
max_range=20, plot_points=200)
View in terms of the coordinates $(X,Z)$ only:
stereoN.plot(chart=cartesian, mapping=Phi, number_values=25,
color={x: 'blue', y: 'orange'},
ambient_coords=(X,Z))
Points on manifolds are introduced via SageMath standard parent/element syntax: element = parent(<data specifying the element>)
. For instance, the North pole is defined as
N = S2((0, 0), chart=spher, name='N')
print(N)
Point N on the 2-dimensional differentiable manifold S^2
spher(N)
sph_plot = spher.plot(chart=cartesian, mapping=Phi, number_values=11,
color='grey', label_axes=False)
sph_plot
Points are endowed with a plot
method:
N.plot(chart=cartesian, mapping=Phi) + sph_plot
S = S2((0, 0), chart=stereoN, name='S')
S.plot(chart=cartesian, mapping=Phi) + sph_plot
spher.frame()
stereoN.frame()
v = S2.vector_field({(stereoN.frame(), stereoN): [1, 0]}, name='v')
v.display(stereoN)
v.plot(chart=stereoN, chart_domain=stereoN)
v_plot = v.plot(chart=cartesian, mapping=Phi, chart_domain=spher,
ranges={th: (0.01, 3.14)},
number_values=11, scale=0.2) + sph_plot
v_plot
w = S2.vector_field({(stereoN.frame(), stereoN): [0, 1]}, name='w')
w.display(stereoN)
w.plot(chart=cartesian, mapping=Phi, chart_domain=spher,
ranges={th: (0.01, 3.14)}, color='red',
number_values=11, scale=0.2) + v_plot
R.<t> = manifolds.RealLine()
c = S2.curve({spher: [2*atan(exp(-t/10)), t]}, (t, -oo, +oo), name='c')
c.display()
c.plot(chart=spher, prange=(-50, 50))
c.plot(chart=stereoN, aspect_ratio=1)
c.plot(chart=stereoN, aspect_ratio=1, prange=(-20, 8), plot_points=200,
color='blue', thickness=2)
c_plot = c.plot(chart=cartesian, mapping=Phi, max_range=40, plot_points=400,
thickness=3) + sph_plot
c_plot
vc = c.tangent_vector_field()
vc.display()
vc.plot(chart=stereoN, number_values=30, scale=0.5, color='brown') \
+ c.plot(chart=stereoN, aspect_ratio=1)
vc.plot(chart=cartesian, mapping=Phi, ranges={t: (-20, 20)},
number_values=30, scale=0.5, color='brown') + c_plot
show(_, viewer='tachyon', aspect_ratio=1, figsize=8)
Other examples of manifold plots are here.