3D Spherical Harmonic Plots

This example demonstrates how to generate a simple 3-dimensional plot of the data in an SHGrid class instance. We start by generating a set of spherical harmonic coefficients that is zero, whith the exception of a single harmonic:

In [1]:
%matplotlib inline
from __future__ import print_function # only necessary if using Python 2.x
import numpy as np
from pyshtools import SHCoeffs

lmax = 30
coeffs = SHCoeffs.from_zeros(lmax)
coeffs.set_coeffs(values=[1], ls=[10], ms=[0])

To plot the data, we first expand it on a grid, and then use the method plot3d():

In [2]:
grid = coeffs.expand()
fig, ax = grid.plot3d(elevation=20, azimuth=30)

Let's try a somewhat more complicated function. Here we will calculate a random realization of a process whose power spectrum follows a power law with exponent -2:

In [3]:
ldata = 30
degrees = np.arange(ldata+1, dtype=float)
degrees[0] = np.inf

power = degrees**(-2)

coeffs2 = SHCoeffs.from_random(power)
grid2 = coeffs2.expand()
fig, ax = grid2.plot3d(elevation=20, azimuth=30)