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
1121def setup (ax ):
12- ax .spines ['right' ].set_color ('none' )
13- ax .spines ['left' ].set_color ('none' )
1422 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 )
1923 ax .set_xlim (0 , 5 )
2024 ax .set_ylim (0 , 1 )
2125 ax .patch .set_alpha (0.0 )
2226
2327
24- fig = plt .figure (figsize = (8 , 5 ))
28+ fig = plt .figure (figsize = (5.7 / 2.54 , 3.8 / 2.54 ))
2529fig .patch .set_alpha (0.0 )
2630n = 7
2731
28- fontsize = 18
29- family = "Source Code Pro"
30-
3132# Null formatter
3233ax = fig .add_subplot (n , 1 , 1 )
3334setup (ax )
3435ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
3536ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
3637ax .xaxis .set_major_formatter (ticker .NullFormatter ())
3738ax .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 )
4040
4141# Fixed formatter
4242ax = fig .add_subplot (n , 1 , 2 )
@@ -48,8 +48,7 @@ def setup(ax):
4848minors = ["" ] + ["%.2f" % (x - int (x )) if (x - int (x ))
4949 else "" for x in np .arange (0 , 5 , 0.25 )]
5050ax .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 )
5352
5453
5554# FuncFormatter can be used as a decorator
@@ -63,8 +62,7 @@ def major_formatter(x, pos):
6362ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
6463ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
6564ax .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 )
6866
6967
7068# FormatStr formatter
@@ -73,39 +71,31 @@ def major_formatter(x, pos):
7371ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
7472ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
7573ax .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 )
7875
7976# Scalar formatter
8077ax = fig .add_subplot (n , 1 , 5 )
8178setup (ax )
8279ax .xaxis .set_major_locator (ticker .AutoLocator ())
8380ax .xaxis .set_minor_locator (ticker .AutoMinorLocator ())
8481ax .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 )
8783
8884# StrMethod formatter
8985ax = fig .add_subplot (n , 1 , 6 )
9086setup (ax )
9187ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
9288ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
9389ax .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 )
9691
9792# Percent formatter
9893ax = fig .add_subplot (n , 1 , 7 )
9994setup (ax )
10095ax .xaxis .set_major_locator (ticker .MultipleLocator (1.00 ))
10196ax .xaxis .set_minor_locator (ticker .MultipleLocator (0.25 ))
10297ax .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 )
10999
110- plt .savefig ("../figures/tick-formatters.pdf" , transparent = True )
100+ plt .savefig ("../figures/tick-formatters.pdf" )
111101# plt.show()
0 commit comments