matplotlib,重复使用不同数字的行

时间:2015-06-12 07:02:47

标签: matplotlib

目的是以最佳方式创建一些详细的数字和摘要数字,您可以在其中比较不同解决方案的相对大小。

为了告诉你我想要什么,我已经编写了以下最小的例子

import matplotlib.pyplot as plt
import numpy as np

parameters = [2, 3]
t = np.linspace(0, 5, 501)

f_all = plt.figure()
a_all = f_all.add_subplot(111)

for p in parameters:
    fig = plt.figure()
    ax = fig.add_subplot(111)
    l, = ax.plot(t, np.sin(p*t)/p,
                 label='$\\omega=%d,\\quad{p}_0=%5.3f$'%(p,1./p))
    a_all.add_line(l)
    ax.legend()
    fig.savefig('pippo_%d'%p)

a_all.legend()
f_all.savefig('pippo_a')

预期结果由3个数字组成,其中两个数字各自为正弦曲线,跨越[0,5]区间,另一个组合两条曲线。

OTOH,下面你可以找到我所拥有的东西。当然有一些东西(一个非常基本的东西!),我错过了。

我可以采用不同的方法,在内循环中使用a_all.plot(...)(测试,它可以工作!),但现在我很奇怪,如果有办法重用一条线,我在这里,寻求你的帮助。

pippo_2

pippo_3

pippo_a

1 个答案:

答案 0 :(得分:2)

保存第一个数字后,

将行添加到$query = $this->createQueryBuilder('p') ->update('MyBundle\Products', 'p') ->set('p.published', ':dateNow') ->setParameter('dateNow', $dateNow) ->getQuery();

a_all

编辑:

然后,您需要为for p in parameters: fig = plt.figure() ax = fig.add_subplot(111) l, = ax.plot(t, np.sin(p*t)/p, label='$\\omega=%d,\\quad{p}_0=%5.3f$'%(p,1./p)) ax.legend() fig.savefig('pippo_%d'%p) a_all.add_line(l) 上的新行设置变换,以将它们移动到新轴。您可能还需要手动设置x和y限制。

这是完整的代码:

a_all

enter image description here

enter image description here

enter image description here