user2401472
user2401472

Reputation: 335

How do I change matplotlib colorbar tick marks to facing outwards?

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()

Upvotes: 5

Views: 9310

Answers (1)

sodd
sodd

Reputation: 12923

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

Upvotes: 12

Related Questions