8000 Fixed a bug in NewScalarFormatter, added lin_collection.py example to · matplotlib/matplotlib@bd79323 · GitHub
[go: up one dir, main page]

Skip to content

Commit bd79323

Browse files
committed
Fixed a bug in NewScalarFormatter, added lin_collection.py example to
backend_driver.py, added newscalarformatter_demo.py to examples. svn path=/trunk/matplotlib/; revision=1261
1 parent cf3fab9 commit bd79323

File tree

3 files changed

+92
-7
lines changed

3 files changed

+92
-7
lines changed

examples/backend_driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'layer_images.py',
3636
'legend_demo.py',
3737
'legend_demo2.py',
38+
'line_collection.py',
3839
'line_styles.py',
3940
'log_demo.py',
4041
'log_test.py',

examples/newscalarformatter_demo.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@ 10000 @ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
# Demonstrating the improvements and options of the proposed new ScalarFormatter
3+
from pylab import *
4+
from matplotlib.ticker import NewScalarFormatter
5+
6+
x=frange(0,1,.01)
7+
f=figure(figsize=(6,6))
8+
f.text(0.5,0.975,'The old formatter',horizontalalignment='center',verticalalignment='top')
9+
subplot(221)
10+
plot(x*1e5+1e10,x*1e-10+1e-5)
11+
subplot(222)
12+
plot(x*1e5,x*1e-4)
13+
subplot(223)
14+
plot(-x*1e5-1e10,-x*1e-5-1e-10)
15+
subplot(224)
16+
plot(-x*1e5,-x*1e-4)
17+
18+
x=frange(0,1,.01)
19+
f=figure(figsize=(6,6))
20+
f.text(0.5,0.975,'The new formatter, default settings',horizontalalignment='center',
21+
verticalalignment='top')
22+
subplot(221)
23+
plot(x*1e5+1e10,x*1e-10+1e-5)
24+
gca().xaxis.set_major_formatter(NewScalarFormatter())
25+
gca().yaxis.set_major_formatter(NewScalarFormatter())
26+
subplot(222)
27+
plot(x*1e5,x*1e-4)
28+
gca().xaxis.set_major_formatter(NewScalarFormatter())
29+
gca().yaxis.set_major_formatter(NewScalarFormatter())
30+
subplot(223)
31+
plot(-x*1e5-1e10,-x*1e-5-1e-10)
32+
gca().xaxis.set_major_formatter(NewScalarFormatter())
33+
gca().yaxis.set_major_formatter(NewScalarFormatter())
34+
subplot(224)
35+
plot(-x*1e5,-x*1e-4)
36+
gca().xaxis.set_major_formatter(NewScalarFormatter())
37+
gca().yaxis.set_major_formatter(NewScalarFormatter())
38+
39+
x=frange(0,1,.01)
40+
f=figure(figsize=(6,6))
41+
f.text(0.5,0.975,'The new formatter, no numerical offset',horizontalalignment='center',
42+
verticalalignment='top')
43+
subplot(221)
44+
plot(x*1e5+1e10,x*1e-10+1e-5)
45+
gca().xaxis.set_major_formatter(NewScalarFormatter(useOffset=False))
46+
gca().yaxis.set_major_formatter(NewScalarFormatter(useOffset=False))
47+
subplot(222)
48+
plot(x*1e5,x*1e-4)
49+
gca().xaxis.set_major_formatter(NewScalarFormatter(useOffset=False))
50+
gca().yaxis.set_major_formatter(NewScalarFormatter(useOffset=False))
51+
subplot(223)
52+
plot(-x*1e5-1e10,-x*1e-5-1e-10)
53+
gca().xaxis.set_major_formatter(NewScalarFormatter(useOffset=False))
54+
gca().yaxis.set_major_formatter(NewScalarFormatter(useOffset=False))
55+
subplot(224)
56+
plot(-x*1e5,-x*1e-4)
57+
gca().xaxis.set_major_formatter(NewScalarFormatter(useOffset=False))
58+
gca().yaxis.set_major_formatter(NewScalarFormatter(useOffset=False))
59+
60+
x=frange(0,1,.01)
61+
f=figure(figsize=(6,6))
62+
f.text(0.5,0.975,'The new formatter, with mathtext',horizontalalignment='center',
63+
verticalalignment='top')
64+
subplot(221)
65+
plot(x*1e5+1e10,x*1e-10+1e-5)
66+
gca().xaxis.set_major_formatter(NewScalarFormatter(useMathText=True))
67+
gca().yaxis.set_major_formatter(NewScalarFormatter(useMathText=True))
68+
subplot(222)
69+
plot(x*1e5,x*1e-4)
70+
gca().xaxis.set_major_formatter(NewScalarFormatter(useMathText=True))
71+
gca().yaxis.set_major_formatter(NewScalarFormatter(useMathText=True))
72+
subplot(223)
73+
plot(-x*1e5-1e10,-x*1e-5-1e-10)
74+
gca().xaxis.set_major_formatter(NewScalarFormatter(useMathText=True))
75+
gca().yaxis.set_major_formatter(NewScalarFormatter(useMathText=True))
76+
subplot(224)
77+
plot(-x*1e5,-x*1e-4)
78+
gca().xaxis.set_major_formatter(NewScalarFormatter(useMathText=True))
79+
gca().yaxis.set_major_formatter(NewScalarFormatter(useMathText=True))
80+
show()

lib/matplotlib/ticker.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,16 @@ def __init__(self, useOffset=True, useMathText=False):
259259
self.format = ''
260260

261261
def __call__(self, x, pos=0):
262-
'Return the format for tick val x at position pos'
263-
self.verify_intervals()
264-
d = abs(self.viewInterval.span())
265-
if self._useOffset: self._set_offset(d)
266-
self._set_orderOfMagnitude(d)
267-
self._set_format()
268-
return self.pprint_val(x)
262+
'Return the format for tick val x at position pos'
263+
if self.locs==None:
264+
return ''
265+
else:
266+
self.verify_intervals()
267+
d = abs(self.viewInterval.span())
268+
if self._useOffset: self._set_offset(d)
269+
self._set_orderOfMagnitude(d)
270+
self._set_format()
271+
return self.pprint_val(x)
269272

270273
def format_data(self,value):
271274
'return a formatted string representation of a number'
@@ -274,6 +277,7 @@ def format_data(self,value):
274277

275278
def get_offset(self):
276279
"""Return scientific notation, plus offset"""
280+
if self.locs==None: return ''
277281
if self.orderOfMagnitude or self.offset:
278282
offsetStr = ''
279283
sciNotStr = ''

0 commit comments

Comments
 (0)
0