Python pylab plot legend 科学写作

Python pylab plot legend scientivic writing

我需要修改图例。 noise_mu 具有类似 1.6e-29 的值,我希望它以这种科学方式精确绘制。不幸的是,我的传说总是以 0.000000000000000000000016 的形式打印它们。我该如何改变它?!

pl.figure('Connectivity', figsize=(16, 9), dpi=80, facecolor="grey", frameon="True")
    pl.ion()
    pl.plot(freqs, con, label="$\mu_N: %.30f$"%noise_mu, linewidth=1.5)
    pl.ylim(0, 1.05)
    pl.xlim(freq1_start-30,freq1_end+30)
    pl.xlabel("Frequency [Hz]", color="black", fontsize=22)
    pl.ylabel("Connectivity Value [ ]", color="black", fontsize=22)
    pl.grid(all)
    xticks = np.arange(freq1_start-30,freq1_end+30,5) # change the ticks accordingly to your ROI
    pl.xticks(xticks)
    yticks = np.arange(0,1.05,0.1)
    pl.yticks(yticks)
    leg = pl.legend(prop={'size':16}, shadow=True, fancybox=True)
    for legobj in leg.legendHandles:
        legobj.set_linewidth(2.5)
    pl.show()

在不指定格式的情况下绘制它

pl.plot(freqs, con, label="$\mu_N: %g$"%noise_mu, linewidth=1.5)

注意 %g 而不是 %.30f

参考:https://docs.python.org/2.4/lib/typesseq-strings.html

我解决了这个问题。不好意思打扰大家了

pl.figure('Connectivity', figsize=(16, 9), dpi=80, facecolor="grey", frameon="True")
pl.ion()
pl.plot(freqs, con, label="$\mu_N: %s$"%noise_mu, linewidth=1.5)
pl.ylim(0, 1.05)
pl.xlim(freq1_start-30,freq1_end+30)
pl.xlabel("Frequency [Hz]", color="black", fontsize=22)
pl.ylabel("Connectivity Value [ ]", color="black", fontsize=22)
pl.grid(all)
xticks = np.arange(freq1_start-30,freq1_end+30,5) # change the ticks accordingly to your ROI
pl.xticks(xticks)
yticks = np.arange(0,1.05,0.1)
pl.yticks(yticks)
leg = pl.legend(prop={'size':16}, shadow=True, fancybox=True)
for legobj in leg.legendHandles:
    legobj.set_linewidth(2.5)
pl.show()

该行必须如下所示:

label="$\mu_N: %s$"%noise_mu

%s 用于科学写作。