2017-04-26 10 views
1

matplotlibを使用して、角度の放射体の正弦値と余弦値のワイヤフレームで3Dヒストグラムをプロットします。それが必要としてプロットは、円を形成:Matplotlib 3Dプロットの円内にない値を外す

enter image description here

今、私はちょうど円とその丘は値の円とその周辺のプロットではなく、持ってしようとしています。 私は

hist[hist==0] = np.nan 

でゼロであるすべての値を解雇しようとしたが、その後、私のプロットは、円の中にもいくつかの値がゼロであるので、ワイヤフレームプロットはもう「地面に触れ」しない場合、この、のように見えます。

enter image description here

だから、円形にし、その周りが、プロットはまだゼロまでのすべての道を行くという値を却下する方法はありますか?

これは私のコードです:

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

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 

cos, sin = np.genfromtxt('out_dhdrls_test0123.csv', delimiter=' ').transpose() 

hist, xedges, yedges = np.histogram2d(cos, sin, bins=50, range=[[-1, 1], [-1, 1]]) 
hist[hist==0] = np.nan 
xpos, ypos = np.meshgrid(xedges[:-1], yedges[:-1]) 
zpos = np.zeros_like(xpos) 
ax.set_xlabel('xlabel') 
ax.set_ylabel('ylabel') 

ax.plot_wireframe(xpos, ypos, hist) 
plt.show() 

答えて

0

あなたは極座標でのヒストグラムを計算する場合があります。これにより、中心からの半径に応じて不要な点を除外しやすくなります。

import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D 
import numpy as np; np.random.seed(1) 

r = np.ones(100)*0.9 
phi = np.random.rand(100)*2.*np.pi 

hist, xedges, yedges = np.histogram2d(r, phi, bins=25, range=[[0, 1.2], [0,2*np.pi*26./25]]) 
R,Phi = np.meshgrid(xedges[:-1], yedges[:-1]) 
X = R*np.cos(Phi) 
Y = -R*np.sin(Phi) 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 
X[(R < 0.75) | (R > 1)] = np.nan 
ax.plot_surface(X,Y, hist.T, alpha=0.2) 
ax.plot_wireframe(X,Y, hist.T) 
plt.show() 

enter image description here

関連する問題