remove colorbar from figure in matplotlib
I am not quite getting how to use this answer practically.
In my program, I need to produce 5 plots. 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...
I am less excited that each plot has 1 additional colorbar. 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.