python 画宇宙

python 画宇宙_第1张图片

import numpy as np 
from scipy import stats 
import math as ma
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
n = 10 
rate= 3
Junksum = 1000 
time = 1000
R = 5 
ER = 6000
t = np.arange(n) 
kurt = stats.poisson.pmf(t , rate)
kurt /= sum(kurt)
num = np.ones(n , dtype = int) 
Junksum -= n 
tmp = Junksum
while Junksum:
    ma = 0  
    for i  in range(n):
        tt = num[i]
        q = kurt[i]*kurt[i]/(tt)/(tt+1)
        if ma < q:
            ma = q 
            pos = i 
    num[pos] += 1
    Junksum -= 1
x = [] ; y = [] ; z = []
for i  in range(n):
    for j in range(num[i]):
        alpha = 2*np.random.rand()*np.pi 
        beta  = 2*np.random.rand()*np.pi
        r = (np.random.rand() + i)*300 + ER + 1000 
        xx = r*np.cos(alpha)*np.sin(beta)
        yy = r*np.cos(alpha)*np.cos(beta)
        zz = r*np.sin(alpha)
        if(zz > ER):
            ttt = np.random.rand()
            if ttt > 0.5:
                continue 
        x.append(xx)
        y.append(yy)
        z.append(zz)
Junksum = tmp 

for i  in range(Junksum):
    alpha =  2*np.random.rand()*np.pi 
    r = (np.random.rand() + i/100)*3000 + ER + 3000
    xx = r*np.cos(alpha)
    yy =  r*np.sin(alpha) 
    zz = 0 
    x.append(xx)
    y.append(yy)
    z.append(zz)
x = np.array(x) 
y = np.array(y) 
z = np.array(z)

fig = plt.figure()
ax = fig.gca(projection = '3d' , axisbg='k')
u = np.linspace(0,2*np.pi , 100)
v = np.linspace(0,2*np.pi, 100)
X = ER*np.outer(np.cos(u) , np.sin(v))
Y = ER*np.outer(np.sin(u) , np.sin(v))
Z = ER*np.outer(np.ones(np.size(u)),np.cos(v))
    
surf = ax.plot_surface(X , Y , Z , rstride=1, cstride=1, color ='b',
                       linewidth=0, antialiased=False)
ax.scatter(x, y ,z, zdir='z' ,c='w',edgecolors = 'w' )
plt.axis('off')
ax.set_zlim(-16000,16000)
ax.set_xlim(-16000,16000)
ax.set_ylim(-16000,16000)
plt.show()


你可能感兴趣的:(python 画宇宙)