2014-06-09 2 views
5

내가 어떤 데이터 포인트 (X, Y, Z, 반경)와 산포도를 만들려고 노력하고 있어요 분야 이것은까지 지금 내 결과입니다분산 레이블 플롯 3D 및

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

x = np.random.rand(20) 
y = np.random.rand(20) 
z = np.random.rand(20) 
r = np.random.rand(20) 


plt.rc('text', usetex=True) 
plt.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"] 

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

ax.scatter(x, y, z, s=np.pi*r**2*100, c='blue', alpha=0.75) 

ax.set_xlabel(r'$x$ $\left[\frac{\text{Mpc}}{h}\right]$') 
ax.set_ylabel(r'$y$ $\left[\frac{\text{Mpc}}{h}\right]$') 
ax.set_zlabel(r'$z$ $\left[\frac{\text{Mpc}}{h}\right]$') 

#plt.savefig('spheres.png') 

plt.show() 

http://www.file-upload.net/download-9033814/spheres.png.html

x- 및 y- 레이블이 틱과 겹치지 않게하려면이 플롯을 어떻게 향상시킬 수 있습니까?

이 3D 플롯에는 영역 대신 구체를 만들 가능성이 있습니까?

답변

8

here과 같이 각 위치에 하나씩 그려 원형 마커 대신 구를 사용하는 플롯을 만들 수 있습니다. 다음 예는 다음과 같습니다

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

def drawSphere(xCenter, yCenter, zCenter, r): 
    #draw sphere 
    u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j] 
    x=np.cos(u)*np.sin(v) 
    y=np.sin(u)*np.sin(v) 
    z=np.cos(v) 
    # shift and scale sphere 
    x = r*x + xCenter 
    y = r*y + yCenter 
    z = r*z + zCenter 
    return (x,y,z) 


x = 10*np.random.rand(20) 
y = 10*np.random.rand(20) 
z = 10*np.random.rand(20) 
r = np.random.rand(20) 


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

# draw a sphere for each data point 
for (xi,yi,zi,ri) in zip(x,y,z,r): 
    (xs,ys,zs) = drawSphere(xi,yi,zi,ri) 
    ax.plot_wireframe(xs, ys, zs, color="r") 


plt.show() 

spheres in 3D plot

설명 here로 두 번째 줄을 추가 레이블 위치 문제의 시도를 해결하려면.

+0

라텍스 글꼴을 사용하기 때문에 레이블 문제는 어떻게 든 해결할 수 없습니다 ...하지만 와이어 프레임 아이디어에 감사드립니다! – Andy