Mep12 ticks and spines #8212

Merged
merged 4 commits into from Mar 7, 2017
@@ -1,8 +1,12 @@
"""
-Basic demo of axis spines.
-
-This demo compares a normal axes, with spines on all four sides, and an axes
-with spines only on the left and bottom.
+======
+Spines
+======
+
+This demo compares:
+ - normal axes, with spines on all four sides;
+ - an axes with spines only on the left and bottom;
+ - an axes using custom bounds to limit the extent of the spine.
"""
import numpy as np
import matplotlib.pyplot as plt
@@ -11,7 +15,7 @@
x = np.linspace(0, 2 * np.pi, 100)
y = 2 * np.sin(x)
-fig, (ax0, ax1) = plt.subplots(nrows=2)
+fig, (ax0, ax1, ax2) = plt.subplots(nrows=3)
ax0.plot(x, y)
ax0.set_title('normal spines')
@@ -26,7 +30,17 @@
ax1.yaxis.set_ticks_position('left')
ax1.xaxis.set_ticks_position('bottom')
+ax2.plot(x, y)
+
+# Only draw spine between the y-ticks
+ax2.spines['left'].set_bounds(-1, 1)
+# Hide the right and top spines
+ax2.spines['right'].set_visible(False)
+ax2.spines['top'].set_visible(False)
+# Only show ticks on the left and bottom spines
+ax2.yaxis.set_ticks_position('left')
+ax2.xaxis.set_ticks_position('bottom')
+
# Tweak spacing between subplots to prevent labels from overlapping
plt.subplots_adjust(hspace=0.5)
-
plt.show()
@@ -1,4 +1,8 @@
"""
+==============
+Dropped spines
+==============
+
Demo of spines offset from the axes (a.k.a. "dropped spines").
"""
import numpy as np
@@ -1,5 +1,9 @@
"""
-Show the different tick formatters
+===============
+Tick formatters
+===============
+
+Show the different tick formatters.
"""
import numpy as np
@@ -1,5 +1,9 @@
"""
-Show the different tick locators
+=============
+Tick locators
+=============
+
+Show the different tick locators.
"""
import numpy as np
@@ -1,6 +1,7 @@
"""
-
-Basic demo showing how to set tick labels to values of a series.
+=========================================
+Setting tick labels from a list of values
+=========================================
Using ax.set_xticks causes the tick labels to be set on the currently
chosen ticks. However, you may want to allow matplotlib to dynamically
@@ -28,6 +29,8 @@ def format_fn(tick_val, tick_pos):
return labels[int(tick_val)]
else:
return ''
+
+
ax.xaxis.set_major_formatter(FuncFormatter(format_fn))
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
ax.plot(xs, ys)
@@ -1,4 +1,8 @@
"""
+===========================
+Rotating custom tick labels
+===========================
+
Demo of custom tick-labels with user-defined rotation.
"""
import matplotlib.pyplot as plt