3
3
# Author: Nicolas P. Rougier
4
4
# License: BSD
5
5
# ----------------------------------------------------------------------------
6
+ import pathlib
7
+
6
8
import numpy as np
9
+ import matplotlib as mpl
7
10
import matplotlib .pyplot as plt
8
11
import matplotlib .ticker as ticker
9
12
13
+
14
+ mpl .style .use ([
15
+ pathlib .Path (__file__ ).parent / '../styles/base.mplstyle' ,
16
+ pathlib .Path (__file__ ).parent / '../styles/ticks.mplstyle' ,
17
+ ])
18
+
19
+
10
20
# Setup a plot such that only the bottom spine is shown
11
21
def setup (ax ):
12
- ax .spines ['right' ].set_color ('none' )
13
- ax .spines ['left' ].set_color ('none' )
14
22
ax .yaxis .set_major_locator (ticker .NullLocator ())
15
- ax .spines ['top' ].set_color ('none' )
16
- ax .xaxis .set_ticks_position ('bottom' )
17
- ax .tick_params (which = 'major' , width = 1.00 , length = 5 )
18
- ax .tick_params (which = 'minor' , width = 0.75 , length = 2.5 , labelsize = 10 )
19
23
ax .set_xlim (0 , 5 )
20
24
ax .set_ylim (0 , 1 )
21
25
ax .patch .set_alpha (0.0 )
22
26
23
27
24
- fig = plt .figure (figsize = (8 , 5 ))
28
+ fig = plt .figure (figsize = (5.7 / 2.54 , 3.8 / 2.54 ))
25
29
fig .patch .set_alpha (0.0 )
26
30
n = 7
27
31
28
- fontsize = 18
29
- family = "Source Code Pro"
30
-
31
32
# Null formatter
32
33
ax = fig .add_subplot (n , 1 , 1 )
33
34
setup (ax )
34
35
ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
35
36
ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
36
37
ax .xaxis .set_major_formatter (ticker .NullFormatter ())
37
38
ax .xaxis .set_minor_formatter (ticker .NullFormatter ())
38
- ax .text (0.0 , 0.1 , "ticker.NullFormatter()" , family = family ,
39
- fontsize = fontsize , transform = ax .transAxes )
39
+ ax .text (0.0 , 0.1 , "ticker.NullFormatter()" , transform = ax .transAxes )
40
40
41
41
# Fixed formatter
42
42
ax = fig .add_subplot (n , 1 , 2 )
@@ -48,8 +48,7 @@ def setup(ax):
48
48
minors = ["" ] + ["%.2f" % (x - int (x )) if (x - int (x ))
49
49
else "" for x in np .arange (0 , 5 , 0.25 )]
50
50
ax .xaxis .set_minor_formatter (ticker .FixedFormatter (minors ))
51
- ax .text (0.0 , 0.1 , "ticker.FixedFormatter(['', '0', '1', ...])" ,
52
- family = family , fontsize = fontsize , transform = ax .transAxes )
51
+ ax .text (0.0 , 0.1 , "ticker.FixedFormatter(['', '0', '1', ...])" , transform = ax .transAxes )
53
52
54
53
55
54
# FuncFormatter can be used as a decorator
@@ -63,8 +62,7 @@ def major_formatter(x, pos):
63
62
ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
64
63
ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
65
64
ax .xaxis .set_major_formatter (major_formatter )
66
- ax .text (0.0 , 0.1 , 'ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)' ,
67
- family = family , fontsize = fontsize , transform = ax .transAxes )
65
+ ax .text (0.0 , 0.1 , 'ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)' , transform = ax .transAxes )
68
66
69
67
70
68
# FormatStr formatter
@@ -73,39 +71,31 @@ def major_formatter(x, pos):
73
71
ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
74
72
ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
75
73
ax .xaxis .set_major_formatter (ticker .FormatStrFormatter (">%d<" ))
76
- ax .text (0.0 , 0.1 , "ticker.FormatStrFormatter('>%d<')" ,
77
- family = family , fontsize = fontsize , transform = ax .transAxes )
74
+ ax .text (0.0 , 0.1 , "ticker.FormatStrFormatter('>%d<')" , transform = ax .transAxes )
78
75
79
76
# Scalar formatter
80
77
ax = fig .add_subplot (n , 1 , 5 )
81
78
setup (ax )
82
79
ax .xaxis .set_major_locator (ticker .AutoLocator ())
83
80
ax .xaxis .set_minor_locator (ticker .AutoMinorLocator ())
84
81
ax .xaxis .set_major_formatter (ticker .ScalarFormatter (useMathText = True ))
85
- ax .text (0.0 , 0.1 , "ticker.ScalarFormatter()" ,
86
- family = family , fontsize = fontsize , transform = ax .transAxes )
82
+ ax .text (0.0 , 0.1 , "ticker.ScalarFormatter()" , transform = ax .transAxes )
87
83
88
84
# StrMethod formatter
89
85
ax = fig .add_subplot (n , 1 , 6 )
90
86
setup (ax )
91
87
ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
92
88
ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
93
89
ax .xaxis .set_major_formatter (ticker .StrMethodFormatter ("{x}" ))
94
- ax .text (0.0 , 0.1 , "ticker.StrMethodFormatter('{x}')" ,
95
- family = family , fontsize = fontsize , transform = ax .transAxes )
90
+ ax .text (0.0 , 0.1 , "ticker.StrMethodFormatter('{x}')" , transform = ax .transAxes )
96
91
97
92
# Percent formatter
98
93
ax = fig .add_subplot (n , 1 , 7 )
99
94
setup (ax )
100
95
ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
101
96
ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
102
97
ax .xaxis .set_major_formatter (ticker .PercentFormatter (xmax = 5 ))
103
- ax .text (0.0 , 0.1 , "ticker.PercentFormatter(xmax=5)" ,
104
- family = family , fontsize = fontsize , transform = ax .transAxes )
105
-
106
- # Push the top of the top axes outside the figure because we only show the
107
- # bottom spine.
108
- fig .subplots_adjust (left = 0.05 , right = 0.95 , bottom = 0.05 , top = 1.05 )
98
+ ax .text (0.0 , 0.1 , "ticker.PercentFormatter(xmax=5)" , transform = ax .transAxes )
109
99
110
- plt .savefig ("../figures/tick-formatters.pdf" , transparent = True )
100
+ plt .savefig ("../figures/tick-formatters.pdf" )
111
101
# plt.show()
0 commit comments