Skip to content

Mep12 ticks and spines #8212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions examples/ticks_and_spines/spines_demo.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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')
Expand All @@ -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()
4 changes: 4 additions & 0 deletions examples/ticks_and_spines/spines_demo_dropped.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""
==============
Dropped spines
==============

Demo of spines offset from the axes (a.k.a. "dropped spines").
"""
import numpy as np
Expand Down
6 changes: 5 additions & 1 deletion examples/ticks_and_spines/tick-formatters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""
Show the different tick formatters
===============
Tick formatters
===============

Show the different tick formatters.
"""

import numpy as np
Expand Down
6 changes: 5 additions & 1 deletion examples/ticks_and_spines/tick-locators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""
Show the different tick locators
=============
Tick locators
=============

Show the different tick locators.
"""

import numpy as np
Expand Down
7 changes: 5 additions & 2 deletions examples/ticks_and_spines/tick_labels_from_values.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions examples/ticks_and_spines/ticklabels_demo_rotation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""
===========================
Rotating custom tick labels
===========================

Demo of custom tick-labels with user-defined rotation.
"""
import matplotlib.pyplot as plt
Expand Down