Revision: 4932
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4932&view=rev
Author:   jdh2358
Date:     2008-02-02 13:32:21 -0800 (Sat, 02 Feb 2008)

Log Message:
-----------
added manual axis example

Added Paths:
-----------
    trunk/matplotlib/examples/manual_axis.py

Added: trunk/matplotlib/examples/manual_axis.py
===================================================================
--- trunk/matplotlib/examples/manual_axis.py                            (rev 0)
+++ trunk/matplotlib/examples/manual_axis.py    2008-02-02 21:32:21 UTC (rev 
4932)
@@ -0,0 +1,57 @@
+"""
+matplotlib is fairly rigid about how and where it draws it xaxis and
+yaxis, and it is a frequent request to be able to place these in other
+locations.  While it is not possible to customize matplotlib's
+internal axis objects in this way, it is not too hard to simply turn
+them off and draw your own axis lines, tick lines, and tick labels
+where and how you want them
+"""
+
+import numpy as np
+from pylab import figure, show
+import matplotlib.lines as lines
+
+def make_xaxis(ax, yloc, offset=0.05, **props):
+    xmin, xmax = ax.get_xlim()
+    locs = [loc for loc in ax.xaxis.get_majorticklocs()
+            if loc>=xmin and loc<=xmax]
+    tickline, = ax.plot(locs, [yloc]*len(locs),linestyle='',
+            marker=lines.TICKDOWN, **props)
+    axline, = ax.plot([xmin, xmax], [yloc, yloc], **props)
+    tickline.set_clip_on(False)
+    axline.set_clip_on(False)
+    for loc in locs:
+        ax.text(loc, yloc-offset, '%1.1f'%loc,
+                horizontalalignment='center',
+                verticalalignment='top')
+
+def make_yaxis(ax, xloc=0, offset=0.05, **props):
+    ymin, ymax = ax.get_ylim()
+    locs = [loc for loc in ax.yaxis.get_majorticklocs()
+            if loc>=ymin and loc<=ymax]
+    tickline, = ax.plot([xloc]*len(locs), locs, linestyle='',
+            marker=lines.TICKLEFT, **props)
+    axline, = ax.plot([xloc, xloc], [ymin, ymax], **props)
+    tickline.set_clip_on(False)
+    axline.set_clip_on(False)
+
+    for loc in locs:
+        ax.text(xloc-offset, loc, '%1.1f'%loc,
+                verticalalignment='center',
+                horizontalalignment='right')
+
+
+props = dict(color='black', linewidth=2, markeredgewidth=2)
+x = np.arange(200.)
+y = np.sin(2*np.pi*x/200.) + np.random.rand(200)-0.5
+fig = figure(facecolor='white')
+ax = fig.add_subplot(111, frame_on=False)
+ax.axison = False
+ax.plot(x, y, 'd', markersize=8, markerfacecolor='blue')
+ax.set_xlim(0, 200)
+ax.set_ylim(-1.5, 1.5)
+make_xaxis(ax, 0, offset=0.1, **props)
+make_yaxis(ax, 0, offset=5, **props)
+fig.savefig('manual_axis.png', dpi=100, facecolor='white', edgecolor='white')
+show()
+


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to