本文介绍了Matplotlib:如何删除轮廓的clabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

As we know that we can remove the collections of contour/contourf. But how can I remove the contour's 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 的标签仍然存在于第二个 png 中.所以我想同时删除clabel.

The clabel of first png still exists in second png. So i want to remove clabel meanwhile.

推荐答案

您可以对 contour 行执行与已经执行的完全相同的操作.最小示例:

You can do the exact same as you are already doing for the contour lines. Minimal example:

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

这篇关于Matplotlib:如何删除轮廓的clabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 20:53