The ground state of the free ion is $^4F$ but is $^4A_2 (t_{2g}^3)$ in a cubic field such as in an octahedral complex with $O_h$ symmetry. This term is shown on the abscissa of the Tanabe-Sugano plot. Thus, even though there is an energy difference between the free ion and when it is in an octahedral field, this is not shown in the plot. The lines representing the higher energy states measure the increase in energy from the ground state
The way to calculate the term symbol for the free ion is explained in detail in many textbooks and in my answer to How does one find the ground-state term symbol for a configuration that is exactly half-filled? .
Why the ground state term symbol is $^4A_2$ in an octahedral complex does need some explanation, however.
In $O_h$ (and $T_d$) point groups the highest dimension of an irreducible representation is three-fold; Mulliken symbol T. As a result the states with orbital degeneracies greater than this e.g. $D, F, G..$ etc. must split into new terms of degeneracy no greater than three.
The calculation for S, P, D, F, G etc. terms is outlined below with an example of F terms.
The effect that the symmetry imposed by the ligands has on the d-orbitals means that these have to be rotated, inverted or reflected according to the operations of the point group. This does not change the energy as it corresponds only to a change in the direction of the axes. Operating this way leads to a reducible representation that is then analysed to obtain its makeup as irreducible representations (irreps).
In $O_h$ the symmetry operations are $E, C_3, C_2, C_4, i, S_4,S_6, \sigma_h, \sigma_d$. The equations to use for rotation are shown in the notes below.
Applying these operations produces the following reducible representation for an F term with orbital angular momentum $L=3$.
$$ \begin{array}{c|cccccccccc}
O_h & E & 8C_3 & 6C_2 & 6C_4 & 3C_2 & i & 6S_4 & 8S_6 & 3\sigma_h & 6\sigma_d \\
\hline
\chi = & 7 & 1 & -1 & -1 &-1 & 7 & -1 & 1 & -1 & -1 \
\end{array}$$
Using the tabular method (see my answer to this question Understanding group theory easily and quickly ) produces the irreps $A_{2g}+T_{1g}+T_{2g}$. Thus an $F$ state splits into a non-degenerate $A_{2g}$ ground state and two triply degenerate states of higher energy. The splitting of other terms (S, D, G etc) is determined in a similar manner.
As the d orbitals are inherently ‘gerade’ or g this subscript is usually dropped from terms in the Tanabe-Sugano plots. Unless spin-orbit coupling is exceptionally strong the spin of the final states is the same as that of the free ion.
The next table shows some free ion and $O_h$ terms.
$$ \begin{array}{clcr}
\text{Free ion} ~~& ~~ O_h\\
\hline
S & A_{1g}\\
P & T_{1g}\\
D & E_g + T_{2g}\\
F & A_{2g} + T_{1g} + T_{2g}\\
G & A_{1g} + E_g + T_{1g} + T_{2g}\\
H & E_g + 2T_{1g} + T_{2g}
\end{array}$$
Using spherical harmonics to produce the energy splitting, which means calculating the potential energy and wavefunctions, is significantly harder and is only sketched.(See Balhausen, 'Introduction to Ligand Field Theory' for all the gory details.)
We suppose that the potential is caused by 6 charges around the central ion, and choose to use the sum of spherical harmonics $Y_l^m$ to form the potential since these are solutions to a problem of full spherical symmetry. The general potential for i electrons is thus $V=\sum_i\sum_l\sum_m Y_l^m(\theta_i\phi_i)R_{nl}(r_i)$ where the R is the radial function which can be dropped from now on as a common factor. The specific potential must transform as the totally symmetric representation of the point group of the molecule, ($A_{1g}$ in $O_h$) because the Hamiltonian must remain totally symmetric under all symmetry operations. It turns out that only terms in $l=0, 2, 4$ can contribute to the potential. The $l=0$ term is the largest but as it is spherically symmetric it has little effect on electronic properties as it only shifts energy levels. The $l=2$ harmonics produce irreps only of $E_g$ and $T_{2g}$, so are not suitable as the totally symmetric representation is absent, but the $l=4$ harmonics produce irreps of $A_{1g},~ E_g,~ T_{1g}$ and $T_{2g}$ which means that there is a linear transform of $Y_4^m$ that transforms as $A_{ig}$.
If the $C_4$ axis is taken as the axis to be quantised then the potential $V_4$ of $A_{1g} $ symmetry (excluding that from $l=0$) is proportional to a linear combination of the harmonics $V_4 \approx Y_4^0+b( Y_4^{+4}+Y_4^{-4})$, b is a constant. (These are the only harmonics that satisfy $\hat C_4 V_4=V_4$.)
To find the wavefunctions we use the fact that the d orbitals transform as $E_g$ and $T_{2g}$ in $O_h$. These can be combined to produce the familiar ‘real’ d orbitals shown in textbooks, $ d_{z^2}, d_{x^2-y^2} $ etc, by quantising along the $C_4$ axis.
The energy splitting $e_g-t_{2g}$ of a single electron in a d orbital e.g. $\ce{Ti^{3+}}$, is conventionally set to $\Delta = 10Dq$ and is positive. The energy of each level calculated as
$E_{eg} = \epsilon_0 +\int \phi^*(e_g)V\phi(e_g)d\tau$
and
$E_{t2g}=\epsilon_0 +\int \phi^*(t_{2g})V\phi(t_{2g})d\tau=-4Dq$
where $\epsilon_0$ is the spherically symmetric part of the potential. The energy gap is then $10Dq=E_{eg}-E_{t2g}$ and when all energy levels are filled with 10 electrons (an S state) then $0=4E_{eg}+6E_{t2g}$ from which $E_{eg}= 6Dq$ and $E_{t2g}=-4Dq$.
As the electron density of the $e_g$ orbitals are directed towards the ligands these are of higher energy than the $t_{2g}$.
Notes:
For quantum number k these relationships can be used with any point group because all point groups are subgroups of a sphere’s symmetry. Remember that $C_n$, is rotation by $2\pi/n$ radians.
$$
\chi(E)= 2k+1\\
\chi(C(x)) = \frac{\sin((k+1/2)x)}{\sin(x/2)}\\
\chi(i) = \pm (2k+1)\\
\chi(S(x)) = \frac{\sin((k+1/2)(x+\pi))}{\sin((x+\pi)/2)}\\
\chi(\sigma)=\pm \sin((k+1/2)\pi)
$$
The + sign is used with gerade, - with ungerade.