本文介绍了绘制时马修特征交叉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要绘制各种 q 的 mathieu 特征参数.该图应显示长笛"形状,从左侧宽到右侧非常窄.下面的代码做到了这一点,但它也引入了一些带间跳跃(从绘制的图中很明显).我该如何解决这个问题?

谢谢!

上午

将 numpy 导入为 np将 scipy 导入为 sp将 scipy.special 导入为 spfun从 matplotlib 导入 pyplot 作为 pltuplim =120#E_recNpts = 1000状态=8q = np.linspace(0, uplim/4.0, Npts)EA = np.zeros([Npts,Nstates])EB = np.zeros([Npts,Nstates])U = 4*q打印 np.shape(EA) #plt.fill_between(U, EA[:,i], EB[:,i]) #plt.plot(U,Ea,U,Eb)对于 i 在范围内(Nstates):a = spfun.mathieu_a(i,q)b = spfun.mathieu_b(i+1,q)EA[:,i] = a + 2*qEB[:,i] = b + 2*qplt.fill_between(U, EA[:,i], EB[:,i]) #plt.plot(U,Ea,U,Eb)打印 np.shape(EA) #plt.fill_between(U, EA[:,i], EB[:,i]) #plt.plot(U,Ea,U,Eb)plt.show()

EDIT 正如 DSM 和 pv 所指出的,这是一个 scipy 错误.随着您走得更远,故障会变得更糟.我最终做的是从 Mathematica 导出我想要的值表,然后将它们导入 python 并进行插值.不是很好,但有效.

解决方案

我尝试使用最新版本的

这使用 NAG 库的 Mark 27 和 ScipPy 的 1.2.1 版

I need to plot the mathieu characteristic parameters for various q. The plot should show 'flute' shapes going from wide on the left, to very narrow on the right. The code below does this, but it also introduces a handful of inter-band jumps (obvious from the plotted figure). How can I fix this?

Thank you!

AM

import numpy as np
import scipy as sp
import scipy.special as spfun
from matplotlib import pyplot as plt

uplim =120#E_rec
Npts =1000
Nstates =8
q = np.linspace(0, uplim/4.0, Npts)
EA = np.zeros([Npts,Nstates])
EB = np.zeros([Npts,Nstates])
U = 4*q

print np.shape(EA)    #plt.fill_between(U, EA[:,i], EB[:,i]) #plt.plot(U,Ea,U,Eb)
for i in range(Nstates):
    a = spfun.mathieu_a(i,q)
    b = spfun.mathieu_b(i+1,q)
    EA[:,i] = a + 2*q
    EB[:,i] = b + 2*q
    plt.fill_between(U, EA[:,i], EB[:,i]) #plt.plot(U,Ea,U,Eb)

print np.shape(EA)    #plt.fill_between(U, EA[:,i], EB[:,i]) #plt.plot(U,Ea,U,Eb)
plt.show()

EDIT As DSM and pv have pointed out, this is a scipy bug. The glitches get worse as you go out further. What I ended up doing was exporting tables of values that I wanted from Mathematica, and importing them into python and interpolating. Not great, but works.

解决方案

I tried computing this with the latest release of the NAG Library for Python which included a new Mathieu function routine.I pushed a little harder -- more states and a higher value of uplim.

%matplotlib inline
import numpy as np
import scipy as sp
import scipy.special as spfun
from naginterfaces.library import specfun
from matplotlib import pyplot as plt

uplim =150#E_rec
Npts = 4000
Nstates = 10
q = np.linspace(0, uplim/4.0, Npts)
EA = np.zeros([Npts,Nstates])
EB = np.zeros([Npts,Nstates])
U = 4*q

plt.figure(figsize=(15,8))
plt.subplot(1,2,1)
plt.title('Using SciPy')

for i in range(Nstates):
    a = spfun.mathieu_a(i,q)
    b = spfun.mathieu_b(i+1,q)
    EA[:,i] = a + 2*q
    EB[:,i] = b + 2*q
    plt.fill_between(U, EA[:,i], EB[:,i]) #plt.plot(U,Ea,U,Eb)


plt.subplot(1,2,2)
plt.title('Using NAG')

for i in range(Nstates):
    a = [specfun.mathieu_ang_periodic_real(ordval=i, q=qi, parity=0, mode=3)[2] for qi in q]
    b = [specfun.mathieu_ang_periodic_real(ordval=i+1, q=qi, parity=1, mode=3)[2] for qi in q]
    EA[:,i] = a + 2*q
    EB[:,i] = b + 2*q
    plt.fill_between(U, EA[:,i], EB[:,i])

plt.show()

This uses Mark 27 of the NAG Library and version 1.2.1 of ScipPy

这篇关于绘制时马修特征交叉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 02:54