Skip to content

Commit 0bfbb9b

Browse files
committed
DOC: Improved example in docs
1 parent 64ddf60 commit 0bfbb9b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

examples/ticks_and_spines/tick_transform_formatter.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,22 @@ def __call__(self, x):
9292
counts += counts.min()
9393

9494
fig = plt.figure()
95-
fig.subplots_adjust(hspace=0.3)
96-
97-
ax1 = fig.add_subplot(211)
98-
ax2 = fig.add_subplot(212, sharex=ax1, sharey=ax1)
95+
ax1 = fig.add_subplot(111)
96+
ax2 = fig.add_subplot(111, sharex=ax1, sharey=ax1, frameon=False)
9997

10098
ax1.plot(temp_C, counts, drawstyle='steps-mid')
101-
ax2.plot(temp_C, counts, drawstyle='steps-mid')
10299

103100
ax1.xaxis.set_major_formatter(StrMethodFormatter('{x:0.2f}'))
104101

105102
# This step is necessary to allow the shared x-axes to have different
106103
# Formatter and Locator objects.
107104
ax2.xaxis.major = Ticker()
108105
# 0C -> 491.67R (definition), -273.15C (0K)->0R (-491.67F)(definition)
106+
ax2.xaxis.set_major_locator(ax1.xaxis.get_major_locator())
109107
ax2.xaxis.set_major_formatter(
110108
TransformFormatter(LinearTransform(in_start=-273.15, in_end=0,
111109
out_end=491.67),
112110
StrMethodFormatter('{x:0.2f}')))
113-
ax2.xaxis.set_major_locator(ax1.xaxis.get_major_locator())
114111

115112
# The y-axes share their locators and formatters, so only one needs to
116113
# be set
@@ -120,11 +117,12 @@ def __call__(self, x):
120117
ax1.yaxis.set_major_formatter(
121118
TransformFormatter(int, StrMethodFormatter('{x:02X}')))
122119

123-
fig.suptitle('Temperature vs Counts')
124-
ax1.set_xlabel('Temp (\u00B0C)')
120+
ax1.set_xlabel('Temperature (\u00B0C)')
125121
ax1.set_ylabel('Samples (Hex)')
126-
ax2.set_xlabel('Temp (\u00B0R)')
127-
ax2.set_ylabel('Samples (Hex)')
122+
ax2.set_xlabel('Temperature (\u00B0R)')
123+
124+
ax1.xaxis.tick_top()
125+
ax1.xaxis.set_label_position('top')
128126

129127
plt.show()
130128

0 commit comments

Comments
 (0)