Posts Tagged ‘axis’

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

Create a second y-axis in matplotlib

Sunday, December 2nd, 2007

Today I was trying to figure out how to plot two time series with differently scaled values. I found two_scales.py example in the matplotlib examples which describes how to do it.

Here’s a slightly simplified version of the code, and afterward a detailed explanation of what’s going on. (more…)