0

我正在尝试根据参数(alpha)绘制函数的多次迭代,并且我想将参数的值传递给标签,以便标签看起来像 alpha=0.5。这样做是可以的,但我希望 alpha 参数由真正的 alpha 呈现,即 LateX 符号。我怎样才能做到这一点?

这是代码:

#***************
#* Phase angle *    
#***************
def phase_angle(alpha,f_act,f_res):
    phi = numpy.arctan2(2*alpha*(f_act/f_res),(1-(f_act/f_res)**2))

    return phi
#**************************
#* Setting the Parameters *
#**************************
f_min = 1
f_max = 200
f_eig = 75
df=.1
alpha =[0.01,0.05,0.5,1]
#******************
#* Initialization *
#******************
f = numpy.arange(f_min,f_max,df)
Freq = f/f_eig

#************************************
#* Plotting the curve for the phase *
#************************************
# Publishable quality image
ps.set_mode("beamer")

# Plotting the curve for the kinematics
fig = pylab.figure()
host = fig.add_subplot(111)
host.set_title('Typical phase response of a resonant system')
for alpha_i in alpha:
    Phase = phase_angle(alpha_i,f,f_eig)
    host.plot(Freq, Phase, label='\alpha=' + str(alpha_i), linewidth=2)
host.axvline(x=1, linewidth=1.5, color='b')
host.set_xlabel(r"Adimensioned frequency $f$/$f_{wing}$ [$-$]")
host.set_ylabel(r"Phase response $\phi$ [$rad$]")
Phase_pi   = Phase/numpy.pi
y_tick = numpy.arange(0,1.5,0.5)

y_label = [r"$0$", r"$+\frac{\pi}{2}$",   r"$+\pi$"]
host.set_yticks(y_tick*numpy.pi)
host.set_yticklabels(y_label, fontsize=20)
host.set_xlim(0,2.5)
host.set_ylim(top=numpy.pi)
pylab.legend(loc=0)
pylab.tight_layout()
pylab.show()

我认为python在连接时会感到困惑。那么有什么想法吗?

4

1 回答 1

2

在此处输入图像描述使用字符串格式(并记住你的$

for alpha_i in alpha:
    Phase = phase_angle(alpha_i,f,f_eig)
    host.plot(Freq, Phase, label=r'$\alpha = {0}$'.format(alpha_i), linewidth=2)
于 2013-06-23T19:58:10.217 回答