欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

使用python 的matplotlib 画轨道实例

程序员文章站 2023-11-27 21:43:46
如下所示: import numpy as np import matplotlib.pyplot as plt import matplotlib.patches...

如下所示:

使用python 的matplotlib 画轨道实例

import numpy as np 
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from scipy import stats
 
fig = plt.figure()
ax = fig.add_subplot(111, xlim=(0, 10), ylim=(-4, 4))
sx=0;sy=0;r=1.5 ; 
circle = mpatches.circle((sx,sy),r,ec='b',fc = 'b',alpha=0.6)
ax.add_patch(circle)
n = 5
alpha = np.linspace(-np.pi/2,np.pi/2,100)
for i in range(1,n+1):
 a = (i+1)*2
 b = (i+1)
 plt.plot(a*np.cos(alpha),b*np.sin(alpha))
 if i <= 3:
  ax.text(a+1,0,'layer.%d'%(i-1),ha='center',va='center')
rate = 3
jnum = 100
for i in range(jnum):
 data = stats.poisson.rvs(mu = rate, loc = 0 , size = 1)
 while data == 0:
  data = stats.poisson.rvs(mu = rate, loc = 0 , size = 1)
 data = data[0] 
 r = np.random.random()
 beta = (np.random.random()-0.5)*np.pi 
 print beta
 data += r
 a = (data+1)*2*np.cos(beta)
 b = (data+1)*np.sin(beta)
 ax.scatter(a,b, c='y',edgecolors = 'y')
xx = [3.5 , 6.8,6.8]
yy = [-1.8,0.9,3.1]
pp = [1.00,0.85,0.75]
rota = [-45,0,0]
for i in range(3):
 plt.plot((1.5,xx[i]) , (0,yy[i]) , 'r')
 ax.scatter(xx[i],yy[i], c='y',edgecolors = 'b')
 ax.text(xx[i] , yy[i] , 'probability %lf'%pp[i] , ha = 'center' )
tx = np.linspace(0,10,10)
ty = np.linspace(-4,-4,10)
ax.set_xticks(tx)
ax.set_xticklabels((''))
ax.set_yticks(ty)
ax.set_yticklabels((''))
#plt.axis('off')
plt.show()

以上这篇使用python 的matplotlib 画轨道实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。