8000 Axis Labels with offset Spines by cimarronm · Pull Request #4134 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Axis Labels with offset Spines #4134

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 9 commits into from
Mar 12, 2015
Prev Previous commit
Next Next commit
TST: Added test to check that axis labels are located correctly when …
…no tick labels are present and axis spines are offset (see issue #3715)
  • Loading branch information
cimarronm committed Mar 6, 2015
commit 54abca41433f13e24883922a778cc84d0f295f42
38 changes: 36 additions & 2 deletions lib/matplotlib/tests/test_spines.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import numpy as np
from nose.tools import assert_less
import six

import numpy as np
import matplotlib
from matplotlib.testing.decorators import image_comparison
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
from matplotlib.testing.decorators import image_comparison, cleanup


@image_comparison(baseline_images=['spines_axes_positions'])
def test_spines_axes_positions():
Expand Down Expand Up @@ -43,3 +46,34 @@ def test_spines_capstyle():
ax = fig.add_subplot(1,1,1)
ax.set_xticks([])
ax.set_yticks([])


@cleanup
def test_label_without_ticks():
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
plt.subplots_adjust(left=0.3, bottom=0.3)
ax.plot(np.arange(10))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('outward', 30))
ax.spines['right'].set_visible(False)
ax.set_ylabel('y label')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('outward', 30))
ax.spines['top'].set_visible(False)
ax.set_xlabel('x label')
ax.xaxis.set_ticks([])
ax.yaxis.set_ticks([])
plt.draw()

spine = ax.spines['left']
spinebbox = spine.get_transform().transform_path(
spine.get_path()).get_extents()
assert_less(ax.yaxis.label.get_position()[0], spinebbox.xmin,
"Y-Axis label not left of the spine")

spine = ax.spines['bottom']
spinebbox = spine.get_transform().transform_path(
spine.get_path()).get_extents()
assert_less(ax.xaxis.label.get_position()[1], spinebbox.ymin,
"X-Axis label not below the spine")
0