2016-10-05 19 views
1

내가 여기에서 튜토리얼 때라도, 3 차원하기 matplotlib에서 함수 F (X1, X2)을 플롯하려고 반환 : http://glowingpython.blogspot.com/2012/01/how-to-plot-two-variable-functions-with.html3D matplotlib에 다 변수 함수를 그려 봅니다. 빈 그림

내가 코드를 실행하려고하면, 그림은 비어있는 것으로 밝혀 축 출력조차 보이지 않습니다. 나는 누군가가이 행동의 원인을 알아낼 수 있는지 궁금해했다. 나는 파이썬 2.7을 사용하고있다.

from __future__ import division 

from numpy import exp,arange 
from pylab import meshgrid,cm,imshow,contour,clabel,colorbar,axis,title,show 
import math 
from mpl_toolkits.mplot3d import Axes3D 
from matplotlib import cm 
from matplotlib.ticker import LinearLocator, FormatStrFormatter 
import matplotlib.pyplot as plt 
from matplotlib import pylab 
from numpy import arange,array,ones 
from scipy import stats 
import numpy 
import matplotlib.ticker as mtick 
import sys 
import os 


# the function that I'm going to plot 
def z_func(x1,x2): 
return exp(-(1-x1)**2 - 100*((x2-x1**2)**2)) 


x1 = arange(5.0,-5.0,-0.01) 
x2 = arange(-5.0,5.0,0.01) 
X1,X2 = meshgrid(x1, x2) # grid of point 
Z = z_func(X1, X2) # evaluation of the function on the grid 


fig = plt.figure() 
ax = fig.gca(projection='3d') 
surf = ax.plot_surface(X1, X2, Z, rstride=1, cstride=1, cmap=cm.RdBu,linewidth=0, antialiased=False) 

ax.zaxis.set_major_locator(LinearLocator(10)) 
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f')) 

ax.set_xlabel('x-axis') 
ax.set_ylabel('y-axis') 
ax.set_zlabel('z-axis') 
ax.view_init(elev=25, azim=-120) 

fig.colorbar(surf, shrink=0.5, aspect=5) 
plt.show() 

답변

1

당신의 코드는 나를 위해 일한다. 컴퓨터가 계산을 마칠 때까지 기다려야했습니다. 긴 계산은 x1x2 크기 때문입니다. 다음 줄에

x1 = arange(5.0,-5.0,-0.01) 
x2 = arange(-5.0,5.0,0.01) 

:

x1 = arange(5.0,-5.0,-0.1) 
x2 = arange(-5.0,5.0,0.1) 

추신이 라인을 변경하려고 수입품을 준비하는 것이 좋습니다. 다음이 필요합니다.

from numpy import exp, arange 
import matplotlib.pyplot as plt 
from matplotlib.ticker import LinearLocator, FormatStrFormatter 
from pylab import meshgrid 
from mpl_toolkits.mplot3d import Axes3D 
from matplotlib import cm