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