File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"""
2- matplotlib is fairly rigid about how and where it draws it xaxis and
3- yaxis, and it is a frequent request to be able to place these in other
4- locations. While it is not possible to customize matplotlib's
5- internal axis objects in this way, it is not too hard to simply turn
6- them off and draw your own axis lines, tick lines, and tick labels
7- where and how you want them
2+ The techniques here are no longer required with the new support for
3+ spines in matplotlib -- see
4+ http://matplotlib.sourceforge.net/examples/pylab_examples/spine_placement_demo.html.
5+
6+ This example should be considered deprecated and is left just for demo
7+ purposes for folks wanting to make a pseudo-axis
8+
89"""
910
1011import numpy as np
Original file line number Diff line number Diff line change 8080:class:`NullFormatter`
8181 no labels on the ticks
8282
83+ :class:`IndexFormatter`
84+ set the strings from a list of labels
85+
8386:class:`FixedFormatter`
8487 set the strings manually for the labels
8588
@@ -203,6 +206,24 @@ def fix_minus(self, s):
203206 """
204207 return s
205208
209+ class IndexFormatter :
210+ """
211+ format the position x to the nearest i-th label where i=int(x+0.5)
212+ """
213+ def __init__ (self , labels ):
214+ self .labels = labels
215+ self .n = len (labels )
216+ def __call__ (self , x , pos = None ):
217+ 'Return the format for tick val x at position pos; pos=None indicated unspecified'
218+ i = int (x + 0.5 )
219+ if i < 0 :
220+ return ''
221+ elif i >= self .n :
222+ return ''
223+ else :
224+ return self .labels [i ]
225+
226+
206227class NullFormatter (Formatter ):
207228 'Always return the empty string'
208229 def __call__ (self , x , pos = None ):
You can’t perform that action at this time.
0 commit comments