Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6750f68

Browse filesBrowse files
anntzerdstansby
authored andcommitted
Merge pull request matplotlib#8212 from NelleV/MEP12_ticks_and_spines
Mep12 ticks and spines
1 parent 2e5a765 commit 6750f68
Copy full SHA for 6750f68

File tree

Expand file treeCollapse file tree

6 files changed

+43
-10
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+43
-10
lines changed

‎examples/ticks_and_spines/spines_demo.py

Copy file name to clipboardExpand all lines: examples/ticks_and_spines/spines_demo.py
+20-6Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"""
2-
Basic demo of axis spines.
3-
4-
This demo compares a normal axes, with spines on all four sides, and an axes
5-
with spines only on the left and bottom.
2+
======
3+
Spines
4+
======
5+
6+
This demo compares:
7+
- normal axes, with spines on all four sides;
8+
- an axes with spines only on the left and bottom;
9+
- an axes using custom bounds to limit the extent of the spine.
610
"""
711
import numpy as np
812
import matplotlib.pyplot as plt
@@ -11,7 +15,7 @@
1115
x = np.linspace(0, 2 * np.pi, 100)
1216
y = 2 * np.sin(x)
1317

14-
fig, (ax0, ax1) = plt.subplots(nrows=2)
18+
fig, (ax0, ax1, ax2) = plt.subplots(nrows=3)
1519

1620
ax0.plot(x, y)
1721
ax0.set_title('normal spines')
@@ -26,7 +30,17 @@
2630
ax1.yaxis.set_ticks_position('left')
2731
ax1.xaxis.set_ticks_position('bottom')
2832

33+
ax2.plot(x, y)
34+
35+
# Only draw spine between the y-ticks
36+
ax2.spines['left'].set_bounds(-1, 1)
37+
# Hide the right and top spines
38+
ax2.spines['right'].set_visible(False)
39+
ax2.spines['top'].set_visible(False)
40+
# Only show ticks on the left and bottom spines
41+
ax2.yaxis.set_ticks_position('left')
42+
ax2.xaxis.set_ticks_position('bottom')
43+
2944
# Tweak spacing between subplots to prevent labels from overlapping
3045
plt.subplots_adjust(hspace=0.5)
31-
3246
plt.show()

‎examples/ticks_and_spines/spines_demo_dropped.py

Copy file name to clipboardExpand all lines: examples/ticks_and_spines/spines_demo_dropped.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
==============
3+
Dropped spines
4+
==============
5+
26
Demo of spines offset from the axes (a.k.a. "dropped spines").
37
"""
48
import numpy as np

‎examples/ticks_and_spines/tick-formatters.py

Copy file name to clipboardExpand all lines: examples/ticks_and_spines/tick-formatters.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""
2-
Show the different tick formatters
2+
===============
3+
Tick formatters
4+
===============
5+
6+
Show the different tick formatters.
37
"""
48

59
import numpy as np

‎examples/ticks_and_spines/tick-locators.py

Copy file name to clipboardExpand all lines: examples/ticks_and_spines/tick-locators.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""
2-
Show the different tick locators
2+
=============
3+
Tick locators
4+
=============
5+
6+
Show the different tick locators.
37
"""
48

59
import numpy as np

‎examples/ticks_and_spines/tick_labels_from_values.py

Copy file name to clipboardExpand all lines: examples/ticks_and_spines/tick_labels_from_values.py
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
2-
3-
Basic demo showing how to set tick labels to values of a series.
2+
=========================================
3+
Setting tick labels from a list of values
4+
=========================================
45
56
Using ax.set_xticks causes the tick labels to be set on the currently
67
chosen ticks. However, you may want to allow matplotlib to dynamically
@@ -28,6 +29,8 @@ def format_fn(tick_val, tick_pos):
2829
return labels[int(tick_val)]
2930
else:
3031
return ''
32+
33+
3134
ax.xaxis.set_major_formatter(FuncFormatter(format_fn))
3235
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
3336
ax.plot(xs, ys)

‎examples/ticks_and_spines/ticklabels_demo_rotation.py

Copy file name to clipboardExpand all lines: examples/ticks_and_spines/ticklabels_demo_rotation.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
===========================
3+
Rotating custom tick labels
4+
===========================
5+
26
Demo of custom tick-labels with user-defined rotation.
37
"""
48
import matplotlib.pyplot as plt

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.