Matplotlib:如何去除轮廓的clabel

时间:2017-11-01 06:21:47

标签: python matplotlib

我们知道我们可以删除轮廓/轮廓的集合。但是如何移除轮廓的clabel?

fig = plt.figure()
ax = fig.add_subplots(111)
for ivalue in range(10):
    values = alldata [ivalue,:,:]
    cs = plt.contour(x,y,vakues)
    cb = plt.clabel(cs, cs.levels)
     # now remove cs
    for c in cs.collections:
        c.remove()
    # but how can I remove cb?
    plt.savefig('%s.png'%ivalue)

第一个png的clabel仍然存在于第二个png中。所以我想同时删除clabel。

1 个答案:

答案 0 :(得分:3)

您可以执行与contour行相同的操作。最小的例子:

import numpy as np
import matplotlib.pylab as pl

pl.figure()
for i in range(2):
    c  = pl.contour(np.random.random(100).reshape(10,10))
    cl = pl.clabel(c)

    if i == 1:
        pl.savefig('fig.png'.format(i))

双轮廓结果,标签:

enter image description here

将其更改为:

    # Same code as above left out

    if i == 1:
        pl.savefig('fig.png'.format(i))

    for contour in c.collections:
        contour.remove()

    for label in cl:
        label.remove()

enter image description here