the example works very well, but what I have is 10 numbers that I want to put in between 11 ticks. Actually what I havve is a checkerboard (using pcolor) and I want to label the X and Y of each pixel.... and now I am confused with the API to do that... The example uses objects that can provide Locator and Formatter instances, but I just have a sequence of numbers....
Johann Johann Cohen-Tanugi wrote: > thanks a lot! > Johann > > John Hunter wrote: > >> On Sat, Jul 11, 2009 at 1:15 PM, Eric Firing<efir...@hawaii.edu> wrote: >> >> >>> John Hunter wrote: >>> >>> >>>> On Thu, Jul 9, 2009 at 9:44 AM, Johann Cohen-Tanugi<co...@lpta.in2p3.fr> >>>> wrote: >>>> >>>> >>>>> Hello, how can I center axis tick labels, so that the labels ends up at >>>>> the center between 2 ticks. >>>>> >>>>> >>>>> >>>> There is no support for this, though you can left or right align a >>>> label with a single tick:: >>>> >>>> for label in ax.xaxis.get_xticklabels(): >>>> label.set_horizontalalignment('right') >>>> >>>> JDH >>>> >>>> >>> Labels for intervals rather than ticks would be nice to have; this is >>> commonly used for labeling months or years, for example. I don't have time >>> to work on it now, unfortunately. >>> >>> The best way to fake it with present facilities might be to use no labels on >>> the major ticks, place minor ticks half-way between the majors, set their >>> lengths to zero, and label them. >>> >>> >> Nice idea, just committed this example to svn as >> examples/pylab_examples/centered_ticklabels.py >> >> import datetime >> import numpy as np >> import matplotlib >> import matplotlib.dates as dates >> import matplotlib.ticker as ticker >> import matplotlib.pyplot as plt >> >> # load some financial data; apple's stock price >> fh = matplotlib.get_example_data('aapl.npy') >> r = np.load(fh); fh.close() >> r = r[-250:] # get the last 250 days >> >> fig = plt.figure() >> ax = fig.add_subplot(111) >> ax.plot(r.date, r.adj_close) >> >> ax.xaxis.set_major_locator(dates.MonthLocator()) >> ax.xaxis.set_minor_locator(dates.MonthLocator(bymonthday=15)) >> >> ax.xaxis.set_major_formatter(ticker.NullFormatter()) >> ax.xaxis.set_minor_formatter(dates.DateFormatter('%b')) >> >> for tick in ax.xaxis.get_minor_ticks(): >> tick.tick1line.set_markersize(0) >> tick.tick2line.set_markersize(0) >> tick.label1.set_horizontalalignment('center') >> >> imid = len(r)/2 >> ax.set_xlabel(str(r.date[imid].year)) >> plt.show() >> >> > > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full prize > details at: http://p.sf.net/sfu/Challenge > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users