简体   繁体   English

MatPlotLib在颜色栏后添加颜色栏

[英]MatPlotLib adding colorbar after colorbar

remove colorbar from figure in matplotlib 从matplotlib中的图中删除颜色条

I am not quite getting how to use this answer practically. 我不太了解如何实际使用此答案。

In my program, I need to produce 5 plots. 在我的程序中,我需要绘制5个图。 They are all basically the same format. 它们基本上都是相同的格式。 Here is my function: 这是我的功能:

def plot_that(x_vals, y_vals, z_vals, figname, units, efficiency_or_not):
    ui = uniformity_calc(z_vals)
    if efficiency_or_not:
        plt.scatter(x_vals, y_vals, s = 3*max(x_vals), c = z_vals, cmap = 'rainbow', vmin = 0, vmax = 1)
    else:
        plt.scatter(x_vals, y_vals, s = 3*max(x_vals), c = z_vals, cmap = 'rainbow')
    c = plt.colorbar()
    c.set_label(units)

    plt.xlabel('Uniformity: ' + str(round(ui,2)))
    plt.savefig('./'+ figname + '.jpg', dpi = 100)

I am very excited that it works and ultimately I can get all 5 plots into my pdf... 我很高兴它能起作用,最终我可以将所有5个图都放入我的pdf文件中...

I am less excited that each plot has 1 additional colorbar. 令我不高兴的是,每个图都有1个附加的色标。 The first has its own...the second has its own plus the one from the previous figure....the third has its own plus the previous two... 第一个有它自己的...第二个有它自己的加上上图中的一个....第三个有它自己的加上前两个的...

I looked at this solution, but I'm not really seeing a good way to implement it. 我看了这个解决方案,但是我并没有真正看到实现它的好方法。 I understand I need to clear the previous colorbar if there is one...I just really really don't understand how. 我知道如果有一个颜色条,我需要清除之前的颜色条。。。我真的真的不知道如何。

我添加了一行并解决了我的问题:plt.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM