File tree Expand file tree Collapse file tree 4 files changed +36
-6
lines changed
Filter options
Expand file tree Collapse file tree 4 files changed +36
-6
lines changed
Original file line number Diff line number Diff line change @@ -103,8 +103,9 @@ original location:
103
103
* Added the rcParam `axes.fromatter.useoffset ` to control the default value
104
104
of `useOffset ` in `ticker.ScalarFormatter `
105
105
106
-
107
-
106
+ * Added `Formatter ` sub-class `StrMethodFormatter ` which
107
+ does the exact same thing as `FormatStrFormatter `, but for new-style
108
+ formatting strings.
108
109
109
110
.. _changes_in_1_3 :
110
111
Original file line number Diff line number Diff line change @@ -55,9 +55,9 @@ He also increased the performance for all of these functions and plot types.
55
55
56
56
Support for detrending and windowing 2D arrays in mlab
57
57
``````````````````````````````````````````````````````
58
- Todd Jennings added support for 2D arrays in the
58
+ Todd Jennings added support for 2D arrays in the
59
59
:func: `~matplotlib.mlab.detrend_mean `, :func: `~matplotlib.mlab.detrend_none `,
60
- and :func: `~matplotlib.mlab.detrend `, as well as adding
60
+ and :func: `~matplotlib.mlab.detrend `, as well as adding
61
61
:func: `~matplotlib.mlab.apply_window ` which support windowing 2D arrays.
62
62
63
63
Support for strides in mlab
@@ -68,6 +68,11 @@ strides to create memory-efficient 2D arrays. This includes
68
68
array, and :func: `~matplotlib.mlab.stride_windows `, which uses a moving window
69
69
to create a 2D array from a 1D array.
70
70
71
+ Formatter for new-style formatting strings
72
+ ``````````````````````````````````````````
73
+ Added `FormatStrFormatterNewStyle ` which does the same job as
74
+ `FormatStrFormatter `, but accepts new-style formatting strings
75
+ instead of printf-style formatting strings
71
76
72
77
Date handling
73
78
-------------
Original file line number Diff line number Diff line change 7
7
from numpy .testing import assert_almost_equal
8
8
import numpy as np
9
9
import matplotlib
10
+
10
11
import matplotlib .ticker as mticker
11
12
12
13
@@ -24,7 +25,7 @@ def test_MaxNLocator():
24
25
25
26
def test_LinearLocator ():
26
27
loc = mticker .LinearLocator (numticks = 3 )
27
- test_value = np .array ([- 0.8 , - 0.3 , 0.2 ])
28
+ test_value = np .array ([- 0.8 , - 0.3 , 0.2 ])
28
29
assert_almost_equal (loc .tick_values (- 0.8 , 0.2 ), test_value )
29
30
30
31
@@ -57,6 +58,16 @@ def test_use_offset():
57
58
nose .tools .assert_equal (use_offset , tmp_form .get_useOffset ())
58
59
59
60
61
+ def test_formatstrformatter ():
62
+ # test % style formatter
63
+ tmp_form = mticker .FormatStrFormatter ('%05d' )
64
+ nose .tools .assert_equal ('00002' , tmp_form (2 ))
65
+
66
+ # test str.format() style formatter
67
+ tmp_form = mticker .StrMethodFormatter ('{x:05d}' )
68
+ nose .tools .assert_equal ('00002' , tmp_form (2 ))
69
+
70
+
60
71
if __name__ == '__main__' :
61
72
import nose
62
73
nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
Original file line number Diff line number Diff line change @@ -292,7 +292,7 @@ def __call__(self, x, pos=None):
292
292
293
293
class FormatStrFormatter (Formatter ):
294
294
"""
295
- Use a format string to format the tick
295
+ Use an old-style ('%' operator) format string to format the tick
296
296
"""
297
297
def __init__ (self , fmt ):
298
298
self .fmt = fmt
@@ -302,6 +302,19 @@ def __call__(self, x, pos=None):
302
302
return self .fmt % x
303
303
304
304
305
+ class StrMethodFormatter (Formatter ):
306
+ """
307
+ Use a new-style format string (as used by `str.format()`)
308
+ to format the tick. The field formatting must be labeled `x`.
309
+ """
310
+ def __init__ (self , fmt ):
311
+ self .fmt = fmt
312
+
313
+ def __call__ (self , x , pos = None ):
314
+ 'Return the format for tick val *x* at position *pos*'
315
+ return self .fmt .format (x = x )
316
+
317
+
305
318
class OldScalarFormatter (Formatter ):
306
319
"""
307
320
Tick location is a plain old number.
You can’t perform that action at this time.
0 commit comments