Customizing colorbar border color on matplotlib

2019-04-07 01:25发布

问题:

how can I change the colorbar borders so that they are white and not black (externals border and between each segment)?

For example:

x=randint(100, size=(10,10))
cs=contourf(x)
cb=colorbar(cs)

give

but I want :

Thanks

回答1:

edit: Notice the comments below for MPL 1.3 and later.

Add:

cb=colorbar(cs, drawedges=True)

cb.outline.set_color('white')
cb.outline.set_linewidth(2)

cb.dividers.set_color('white')
cb.dividers.set_linewidth(2)


回答2:

As PiQuer mentioned:

cb.outline.set_edgecolor('white')

works nowadays