2016-04-09 42 views
4

放物線f(r)= r ** 2を2D極ヒートマップとしてプロットしたいと思います。私が期待した出力は、私が書かれているenter image description herePythonヒートマップ

コードが

from pylab import* 
from mpl_toolkits.mplot3d import Axes3D 
ax = Axes3D(figure()) 
rad=linspace(0,5,100) 
azm=linspace(0,2*pi,100) 
r,th=meshgrid(rad,azm) 
z=(r**2.0)/4.0 
subplot(projection="polar") 
pcolormesh(r,th, z) 
show() 

です。しかし、このプログラムは、以下の画像を返します。 enter image description here

誰かが助けることができますか?前もって感謝します。

答えて

2

私はあなたが不注意radiuszenithazimuthを混同だと思う:)

これは私がしたいと思うものをプロットします。

import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D 
import numpy as np 

fig = plt.figure() 
ax = Axes3D(fig) 

rad = np.linspace(0, 5, 100) 
azm = np.linspace(0, 2 * np.pi, 100) 
r, th = np.meshgrid(rad, azm) 
z = (r ** 2.0)/4.0 

plt.subplot(projection="polar") 

plt.pcolormesh(th, r, z) 
#plt.pcolormesh(th, z, r) 

plt.plot(azm, r, color='k', ls='none') 
plt.grid() 

plt.show() 

enter image description here

あなたは線グリッド線が必要な場合は、することができます次のようにすべてのシータを追加してください:

plt.thetagrids([theta * 15 for theta in range(360//15)]) 

enter image description here

と、このような、よりラジアルグリッド:

plt.rgrids([.3 * _ for _ in range(1, 17)]) 

enter image description here

PS:numpyのとpyplotがきちんと自分の名前空間を維持します...

関連する問題