I am trying to visualize the log likelihood estimator for normal distribution via python but in vain. I am not sure if its a python issue or formuala issue in the code. Can you kindly have a look?
Letting $\theta_1 = \mu$ and $\theta_2 = \sigma^2$,
$$ L(\theta_1, \theta_2) = \prod\limits_{i=1}^m\dfrac{1}{\sqrt{2\pi\theta_2}}\text{exp}\Big[ -\dfrac{(x_i - \theta_1)^2}{2\theta_2}\Big] \\ = \Big(\dfrac{1}{\sqrt{2\pi\theta_2}}\Big)^{m}\text{exp}\Big[ -\dfrac{ \sum_{i=1}^m(x_i - \theta_1)^2}{2\theta_2}\Big] \\ $$
Taking log on both sides, $$ ln(L(\theta_1, \theta_2)) = - \dfrac{m}{2}\Bigg\{ln(2\pi\theta_2)\Bigg\} - \dfrac{ \sum_{i=1}^m(x_i - \theta_1)^2}{2\theta_2} $$
MWE is here
Reference for expected output (Answer by gregmacfarlane)
Kindly help.
Context: My approach and equations are from this book, page 269, Example 6.4-3.
Update 1:
As calculus pointed, I updated a correction in MWE, still getting similar wrong output.
Update 2:
Found the issue almost still there are problems. It was a programmatic one, that I used X and Y alternatively while shaping Z values. This was due to wrong hint given here from Plotly, so was intriguing, why they were giving Y first and then X.
Wrong code:
Z = np.array(Z).reshape(len(t2),len(t1))
Corrected code:
Z = np.array(Z).reshape((len(t1),len(t2)))
Matplotlib's plot_surface totally required a different approach and was able to solve that also.
Update 3:
Finding the max point in the surface (actually min because its log), gives me correct mean and sigma values, reassuring more the curve is probably correct.

Here is the updated MWE for both figures.
Problems still existing:
- I am always having to have equi sized X and Y. If I reduce X's size, Y also gets reduced in the graph.



