Skip to content

Commit e66091d

Browse files
committed
readded the long lost IndexFormatter
svn path=/trunk/matplotlib/; revision=7213
1 parent b8cb4e7 commit e66091d

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

examples/pylab_examples/manual_axis.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
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

1011
import numpy as np

lib/matplotlib/ticker.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
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+
206227
class NullFormatter(Formatter):
207228
'Always return the empty string'
208229
def __call__(self, x, pos=None):

0 commit comments

Comments
 (0)