python - 从图中删除颜色条

标签 python matplotlib colorbar colormap

我写了一些代码来创建一个光栅对象的 png(self[:] = 一个 np 数组)。 它应该是一种方法,可以轻松地制作情节 代码的问题是它第一次运行良好, 但是当我多次运行这个方法时,我得到了一张有多个图例的图片。

enter image description here

我试过用delaxes去掉它,但是这个传说真的很顽固。
欢迎任何想法如何解决这个问题

代码如下:

    def plot(self,image_out,dpi=150, rotate = 60):
        xur = self.xur()
        xll = self.xll()
        yur = self.yur()
        yll = self.yll()
        fig = plt.figure()
    #tmp = range(len(fig.axes))
    #tmp = tmp[::-1]
    #for x in tmp:
    #    fig.delaxes(fig.axes[x])
        ax = fig.add_subplot(111)
        cax = ax.imshow(self[:],cmap='jet', extent = [yll,yur,xll,xur],
                            interpolation = 'nearest')
        cbar = fig.colorbar()
        plt.xticks(rotation=70)
        plt.tight_layout(pad = 0.25)
        plt.savefig(image_out,dpi=dpi)
        return

最佳答案

你需要关闭情节。 I had this same problem

在plt.savefig后加入plt.close()

关于python - 从图中删除颜色条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24678413/

相关文章:

python - 我正在 python 中进行颜色转换并返回 'False'

python - 除每个列表的第一个值之外的嵌套列表行的总和

python - 在 Python 3(也许是 matplotlib)中绘制革命实体

python - 将白色添加到 pylab 颜色栏默认颜色图

python - 热图上的特定异常值 - matplotlib

python - Matplotlib : the colorbar keeps shrinking

python - numpy 中的聚合时间序列

python - 如何使用python读取HDFS目录中的文件

python - 为什么使用 matplotlib 无法正确显示 CIFAR-10 图像?

Windows 上的 Python Matplotlib : Issue on updating matplotlib to 3. 1.2