Posts Tagged ‘tick labels’

Change distance of tick labels from axis

Thursday, January 17th, 2008

Set the rc parameters using the rc function.


import pylab as p
p.rc(('xtick.major','xtick.minor','ytick.major','ytick.minor'), pad=10)
p.plot([1,2,3])

If you only want to change one of the tick labels, say, the x major ticks, use
p.rc(’xtick.major), pad=10)

When you’re done and want to reset the rc settings, use

p.rcdefaults()

See matplotlibrc for more settings you can change via the rc command.

Change tick locations and labels in ggplot

Sunday, January 13th, 2008

Use the scale_x_continuous (or scale_y_continuous) to change tick locations and labels in ggplot.

Change the ticks:


p = ggplot(diamonds)+aes(x=carat,y=price) +
   scale_x_continuous(breaks=c(1,1.2,1.5,2.5))

Change the ticks and tick labels:

p = ggplot(diamonds)+aes(x=carat,y=price) +
   scale_x_continuous(breaks=c(1,1.2,1.5,2.5), labels=c('a','b','c','d'))