Remove matplotlib color bar borders

How to remove borders on a color panel (or make them thinner)?

I have tried almost any 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 them help when viewing matplotlib shapes, but a saved PDF is even worse.

enter image description here

+4
source share
1 answer

Settings cb.outline.set_visible()- Falsedeletes the contour, both in the figure and in the saved pdf. I noticed that setting the line width to something small was also 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.

+9
source

Source: https://habr.com/ru/post/1569093/


All Articles