如何去除轮廓的标签

问题描述 投票:0回答:1

众所周知,我们可以删除contour/contourf的集合。但是我怎样才能删除轮廓的标签呢?

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。

python matplotlib counter
1个回答
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))

产生双轮廓,标签:

将其更改为:

    # 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()

© www.soinside.com 2019 - 2024. All rights reserved.