在python中绘制多变量log 2基函数

时间:2016-10-01 23:47:43

标签: python matplotlib ln

我需要在python中绘制一个多变量ln函数。该图将在区域x 1,x2∈[-5,5]上显示ln(L 1(x 1,x 2))。模型的简并性将在x 1 -x 2中显示为线条 ln L 1的值不变的平面。

我按照一个教程来完成线性函数的工作。 :

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()

还附加了生成的图像,这对我来说还不是很明智。enter image description here 我想知道如何将其更改为基于ln的情节。另外,我需要在图中添加x和y标签

0 个答案:

没有答案