3
3
# Author: Nicolas P. Rougier
4
4
# License: BSD
5
5
# ----------------------------------------------------------------------------
6
+ import pathlib
7
+
8
+ import numpy as np
9
+ import matplotlib as mpl
6
10
import matplotlib .pyplot as plt
7
11
import matplotlib .ticker as ticker
8
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
+
9
20
# Setup a plot such that only the bottom spine is shown
10
21
11
22
12
23
def setup (ax ):
13
24
"""Set up Axes with just an x-Axis."""
14
- ax .spines ['right' ].set_color ('none' )
15
- ax .spines ['left' ].set_color ('none' )
16
25
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
26
ax .set_xlim (0 , 5 )
22
27
ax .set_ylim (0 , 1 )
23
28
ax .patch .set_alpha (0.0 )
24
29
25
30
26
- fig = plt .figure (figsize = (8 , 5 ))
31
+ fig = plt .figure (figsize = (5.7 / 2.54 , 3.8 / 2.54 ))
27
32
fig .patch .set_alpha (0.0 )
28
33
n = 7
29
34
30
- fontsize = 18
31
- family = "Source Code Pro"
32
-
33
35
# Null formatter
34
36
ax = fig .add_subplot (n , 1 , 1 )
35
37
setup (ax )
36
38
ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
37
39
ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
38
40
ax .xaxis .set_major_formatter (ticker .NullFormatter ())
39
41
ax .xaxis .set_minor_formatter (ticker .NullFormatter ())
40
- ax .text (0.0 , 0.1 , "ticker.NullFormatter()" , family = family ,
41
- fontsize = fontsize , transform = ax .transAxes )
42
+ ax .text (0.0 , 0.1 , "ticker.NullFormatter()" , transform = ax .transAxes )
42
43
43
44
# Fixed formatter
44
45
ax = fig .add_subplot (n , 1 , 2 )
@@ -47,8 +48,7 @@ def setup(ax):
47
48
ax .xaxis .set_major_locator (ticker .FixedLocator (range (6 )))
48
49
majors = ["zero" , "one" , "two" , "three" , "four" , "five" ]
49
50
ax .xaxis .set_major_formatter (ticker .FixedFormatter (majors ))
50
- ax .text (0.0 , 0.1 , "ticker.FixedFormatter(['zero', 'one', 'two', …])" ,
51
- family = family , fontsize = fontsize , transform = ax .transAxes )
51
+ ax .text (0.0 , 0.1 , "ticker.FixedFormatter(['zero', 'one', 'two', …])" , transform = ax .transAxes )
52
52
53
53
54
54
# FuncFormatter can be used as a decorator
@@ -63,8 +63,7 @@ def major_formatter(x, pos):
63
63
ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
64
64
ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
65
65
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 )
66
+ ax .text (0.0 , 0.1 , 'ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)' , transform = ax .transAxes )
68
67
69
68
70
69
# FormatStr formatter
@@ -73,39 +72,31 @@ def major_formatter(x, pos):
73
72
ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
74
73
ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
75
74
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 )
75
+ ax .text (0.0 , 0.1 , "ticker.FormatStrFormatter('>%d<')" , transform = ax .transAxes )
78
76
79
77
# Scalar formatter
80
78
ax = fig .add_subplot (n , 1 , 5 )
81
79
setup (ax )
82
80
ax .xaxis .set_major_locator (ticker .AutoLocator ())
83
81
ax .xaxis .set_minor_locator (ticker .AutoMinorLocator ())
84
82
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 )
83
+ ax .text (0.0 , 0.1 , "ticker.ScalarFormatter()" , transform = ax .transAxes )
87
84
88
85
# StrMethod formatter
89
86
ax = fig .add_subplot (n , 1 , 6 )
90
87
setup (ax )
91
88
ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
92
89
ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
93
90
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 )
91
+ ax .text (0.0 , 0.1 , "ticker.StrMethodFormatter('{x}')" , transform = ax .transAxes )
96
92
97
93
# Percent formatter
98
94
ax = fig .add_subplot (n , 1 , 7 )
99
95
setup (ax )
100
96
ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
101
97
ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
102
98
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 )
99
+ ax .text (0.0 , 0.1 , "ticker.PercentFormatter(xmax=5)" , transform = ax .transAxes )
109
100
110
- plt .savefig ("../figures/tick-formatters.pdf" , transparent = True )
101
+ plt .savefig ("../figures/tick-formatters.pdf" )
111
102
# plt.show()
0 commit comments