I need to plot a multivariable ln function in python. The Plot will show ln (L 1 (x 1 , x 2 )) over the region x 1 , x 2 ∈ [−5, 5]. The model’s degeneracy will show up as lines in the x 1 -x 2 plane where the value of ln L 1 does not change.
I followed a tutorial which does the job for a linear function. :
from __future__ import division
from numpy import exp,arange
from pylab import meshgrid,cm,imshow,contour,clabel,colorbar,axis,title,show
import matplotlib.pyplot as plt
from matplotlib import pylab
from numpy import arange,array,ones
from scipy import stats
import numpy
import sys
import os
import matplotlib.pyplot as plt
from pylab import *
import math
# the function that I'm going to plot
def z_func(x1,x2):
return exp(-(1-x1)**2 - 100*((x2-x1**2)**2))
x1 = linspace(-5.0,5.0,1000)
x2 = linspace(-5.0,5.0,1000)
X1,X2 = meshgrid(x1, x2) # grid of point
Z = z_func(X1, X2) # evaluation of the function on the grid
im = imshow(Z,cmap=cm.RdBu) # drawing the function
# adding the Contour lines with labels
#cset = contour(Z,arange(-1,1.5,0.2),linewidths=2,cmap=cm.Set2)
#clabel(cset,inline=True,fmt='%1.1f',fontsize=10)
#colorbar(im) # adding the colobar on the right
# latex fashion title
title('$L = exp(-(1-x_{1})^2 - 100(x_{2}-x_{1}^2)^2)$')
show()
The generated image is also attached, which is not very sensible to me yet.
I was wondering how do I change it to a ln based plot . Also I need to add x and y labels to the plot