Question

I've noticed on the matplotlib examples gallery that all of their plots featuring vertical colorbars have tick marks on them that face inward,

(i.e. From the edge of the bar into the colored region of the bar).

For the types of plots and colorscales that I am using, it would be much better to have the tick marks facing outwards.

How would I modify this simple example from the matplotlib gallery (see below) to have outward facing tick marks on its colorbar?

from matplotlib.colors import LogNorm
from pylab import *

#normal distribution center at x=0 and y=5
x = randn(100000)
y = randn(100000)+5

hist2d(x, y, bins=40, norm=LogNorm())
colorbar()
show()
Was it helpful?

Solution

Simply set the tick_params for the colorbar:

from matplotlib.colors import LogNorm
from pylab import *

#normal distribution center at x=0 and y=5
x = randn(100000)
y = randn(100000)+5

hist2d(x, y, bins=40, norm=LogNorm())
colorbar().ax.tick_params(axis='y', direction='out')
show()

Colorbar with ticks out

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top