Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 983
user2401472 Avatar asked May 20 '13 11:05

user2401472


1 Answers

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

like image 181
sodd Avatar answered Oct 28 '22 01:10

sodd