Remove colorbar's borders matplotlib

user1830663 picture user1830663 · Dec 27, 2014 · Viewed 7.3k times · Source

How to remove the borders on the colorbar(or make them thinner)?

I tried pretty much every combination of the following:

cb = plt.colorbar(im3,drawedges=False) #or True with next two lines
#cb.outline.set_linewidth(0)
#cb.dividers.set_linewidth(0)

cb.solids.set_rasterized(True)
cb.solids.set_edgecolor("face")

#Im saving as pdf
plt.savefig("thing.pdf",dpi=1000, bbox_inches='tight')

Some of these help when viewed with the matplotlib figure, but the saved pdf is even worse.

enter image description here

Answer

snake_charmer picture snake_charmer · Dec 27, 2014

Setting cb.outline.set_visible() to False removes the outline, both in the figure and in the saved pdf. I observed that setting the line's width to something small also was reflected in the output file.

import matplotlib.pyplot as plt
import numpy as np

data = np.random.rand(2,2)
im3 = plt.imshow(data)

cb = plt.colorbar(im3)

cb.outline.set_visible(False)

# this worked on matplotlib 1.3.1
#cb.outline.set_linewidth(0.05)

cb.set_ticks([])

#Im saving as pdf
plt.savefig("thing.pdf",dpi=1000, bbox_inches='tight')

png output, but pdf worked just the same.