Menu

[r540]: / trunk / htdocs / examples / custom_ticker1.py  Maximize  Restore  History

Download this file

31 lines (24 with data), 840 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
"""
The new ticker code was designed to explicity support user customized
ticking. The documentation
http://matplotlib.sourceforge.net/matplotlib.ticker.html details this
process. That code defines a lot of preset tickers but was primarily
designed to be user extensible.
In this example a user defined function is used to format the ticks in
millions of dollars on the y axis
"""
from matplotlib.ticker import FuncFormatter
from matplotlib.matlab import *
x = arange(4)
money = [1.5e5, 2.5e6, 5.5e6, 2.0e7]
def millions(x, pos):
'The two args are the value and tick position'
return '$%1.1fM' % (x*1e-6)
formatter = FuncFormatter(millions)
ax = subplot(111)
ax.yaxis.set_major_formatter(formatter)
bar(x, money)
ax.set_xticks( x + 0.5)
ax.set_xticklabels( ('Bill', 'Fred', 'Mary', 'Sue') )
show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.