Revision: 7257
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7257&view=rev
Author: jdh2358
Date: 2009-07-11 20:18:06 +0000 (Sat, 11 Jul 2009)
Log Message:
-----------
centered ticklabel examples
Added Paths:
-----------
trunk/matplotlib/examples/pylab_examples/centered_ticklabels.py
Added: trunk/matplotlib/examples/pylab_examples/centered_ticklabels.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/centered_ticklabels.py
(rev 0)
+++ trunk/matplotlib/examples/pylab_examples/centered_ticklabels.py
2009-07-11 20:18:06 UTC (rev 7257)
@@ -0,0 +1,44 @@
+# sometimes it is nice to have ticklabels centered. mpl currently
+# associates a label with a tick, and the label can be aligned
+# 'center', 'feft', or 'right' using the horizontal alignment property:
+#
+#
+# for label in ax.xaxis.get_xticklabels():
+# label.set_horizntal_alignment('right')
+#
+#
+# but this doesn't help center the label between ticks. One solution
+# is to "face it". Use the minor ticks to place a tick centered
+# between the major ticks. Here is an example that labels the months,
+# centered between the ticks
+
+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()
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
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-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins