33# Author: Nicolas P. Rougier
44# License: BSD
55# ----------------------------------------------------------------------------
6+ import pathlib
7+
68import numpy as np
9+ import matplotlib as mpl
710import matplotlib .pyplot as plt
811import matplotlib .ticker as ticker
912
13+
14+ mpl .style .use ([
15+ pathlib .Path (__file__ ).parent / '../styles/base.mplstyle' ,
16+ pathlib .Path (__file__ ).parent / '../styles/ticks.mplstyle' ,
17+ ])
18+
19+
1020# Setup a plot such that only the bottom spine is shown
1121
1222
1323def setup (ax ):
14- ax .spines ['right' ].set_color ('none' )
15- ax .spines ['left' ].set_color ('none' )
1624 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 )
2125 ax .set_xlim (0 , 5 )
2226 ax .set_ylim (0 , 1 )
2327 ax .patch .set_alpha (0.0 )
2428
2529
26- fig = plt .figure (figsize = (8 , 5 ))
30+ fig = plt .figure (figsize = (5.7 / 2.54 , 3.8 / 2.54 ))
2731fig .patch .set_alpha (0.0 )
2832n = 7
2933
30- fontsize = 18
31- family = "Source Code Pro"
32-
3334# Null formatter
3435ax = fig .add_subplot (n , 1 , 1 )
3536setup (ax )
3637ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
3738ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
3839ax .xaxis .set_major_formatter (ticker .NullFormatter ())
3940ax .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 )
4242
4343# Fixed formatter
4444ax = fig .add_subplot (n , 1 , 2 )
@@ -50,8 +50,7 @@ def setup(ax):
5050minors = ["" ] + ["%.2f" % (x - int (x )) if (x - int (x ))
5151 else "" for x in np .arange (0 , 5 , 0.25 )]
5252ax .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 )
5554
5655
5756# FuncFormatter can be used as a decorator
@@ -65,8 +64,7 @@ def major_formatter(x, pos):
6564ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
6665ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
6766ax .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 )
7068
7169
7270# FormatStr formatter
@@ -75,39 +73,31 @@ def major_formatter(x, pos):
7573ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
7674ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
7775ax .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 )
8077
8178# Scalar formatter
8279ax = fig .add_subplot (n , 1 , 5 )
8380setup (ax )
8481ax .xaxis .set_major_locator (ticker .AutoLocator ())
8582ax .xaxis .set_minor_locator (ticker .AutoMinorLocator ())
8683ax .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 )
8985
9086# StrMethod formatter
9187ax = fig .add_subplot (n , 1 , 6 )
9288setup (ax )
9389ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
9490ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
9591ax .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 )
9893
9994# Percent formatter
10095ax = fig .add_subplot (n , 1 , 7 )
10196setup (ax )
10297ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
10398ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
10499ax .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 )
111101
112- plt .savefig ("../figures/tick-formatters.pdf" , transparent = True )
102+ plt .savefig ("../figures/tick-formatters.pdf" )
113103# plt.show()
0 commit comments