add a single x tick label

Hi, I have a plot of a time series and I would like to add a single extra tick mark and label to the plot in a different color to the already existing tick marks. Is this possible??
Thanks,
D

It’s fairly easy to do if you want to set the tick locations and labels youself (see http://matplotlib.sourceforge.net/users/artists.html near the end for an overview of the mpl containers like Tick and the attributes they contain).

import matplotlib.pyplot as plt

import numpy as np

fig, ax = plt.subplots(1)

ax.plot(np.random.randn(10,2)*10)

locs = np.arange(2, 10, 2)

labels = [‘%d’%loc for loc in locs]

ticks, labels = plt.xticks(locs, labels)

i = 2

tick1line and tick2line are matplotlib.lines.Line2D instances

ticks[i].tick1line.set_color(‘red’)

ticks[i].tick2line.set_color(‘red’)

labels[i].set_color(‘red’)

plt.show()

If you want to “add a tick” using the existing mpl auto tick locating and labeling infrastructure, it is also possible but you will need to subclass the tick locator.

JDH

···

On Wed, Feb 8, 2012 at 8:42 AM, David Craig <dcdavemail@…287…> wrote:

Hi, I have a plot of a time series and I would like to add a single
extra tick mark and label to the plot in a different color to the
already existing tick marks. Is this possible??
Thanks,