Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove colorbar's borders matplotlib

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

like image 673
user1830663 Avatar asked Dec 26 '14 23:12

user1830663


1 Answers

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.

like image 180
snake_charmer Avatar answered Sep 28 '22 11:09

snake_charmer