# 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 :
%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=, ls=, ms=)


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

In :
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 :
ldata = 30
degrees = np.arange(ldata+1, dtype=float)
degrees = np.inf

power = degrees**(-2)

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