Skip to content

Commit eaa41d8

Browse files
authored
Merge pull request #98 from StefRe/fix/fixed_locator
Fix FixedFormatter
2 parents 2c0fb72 + 7f52e6b commit eaa41d8

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

Diff for: logos/logo2.png

21.8 KB
Loading

Diff for: scripts/tick-formatters.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# Author: Nicolas P. Rougier
44
# License: BSD
55
# ----------------------------------------------------------------------------
6-
import numpy as np
76
import matplotlib.pyplot as plt
87
import matplotlib.ticker as ticker
98

109
# Setup a plot such that only the bottom spine is shown
1110

1211

1312
def setup(ax):
13+
"""Set up Axes with just an x-Axis."""
1414
ax.spines['right'].set_color('none')
1515
ax.spines['left'].set_color('none')
1616
ax.yaxis.set_major_locator(ticker.NullLocator())
@@ -43,20 +43,18 @@ def setup(ax):
4343
# Fixed formatter
4444
ax = fig.add_subplot(n, 1, 2)
4545
setup(ax)
46-
ax.xaxis.set_major_locator(ticker.MultipleLocator(1.0))
4746
ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25))
48-
majors = ["", "0", "1", "2", "3", "4", "5"]
47+
ax.xaxis.set_major_locator(ticker.FixedLocator(range(6)))
48+
majors = ["zero", "one", "two", "three", "four", "five"]
4949
ax.xaxis.set_major_formatter(ticker.FixedFormatter(majors))
50-
minors = [""] + ["%.2f" % (x-int(x)) if (x-int(x))
51-
else "" for x in np.arange(0, 5, 0.25)]
52-
ax.xaxis.set_minor_formatter(ticker.FixedFormatter(minors))
53-
ax.text(0.0, 0.1, "ticker.FixedFormatter(['', '0', '1', ...])",
50+
ax.text(0.0, 0.1, "ticker.FixedFormatter(['zero', 'one', 'two', …])",
5451
family=family, fontsize=fontsize, transform=ax.transAxes)
5552

5653

5754
# FuncFormatter can be used as a decorator
5855
@ticker.FuncFormatter
5956
def major_formatter(x, pos):
57+
"""Return formatted value with 2 decimal places."""
6058
return "[%.2f]" % x
6159

6260

0 commit comments

Comments
 (0)