-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eb5f6e4
BUG: Account for spine position when placing the axis labels if tick …
cimarronm 830d9ad
STY: pep8 fixes
cimarronm 97bbf59
DOC: Modified doctstring of _update_label_position for new functionality
cimarronm c326744
Simplified logic in _update_label_position to use the bounding box of…
cimarronm ef683df
STY: Minor tweak to refactor the spine object out of the spinebbox co…
cimarronm ebb2e63
Handle plots with no spines or transformations with non-standard spines
cimarronm 54abca4
TST: Added test to check that axis labels are located correctly when …
cimarronm 407e362
STY: pep8 fixes to test_spines
cimarronm f49a5b6
TST: Removed test_spines.py from pep8 excluded list since it is passi…
cimarronm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,83 @@ | ||
from __future_ 8000 _ import (absolute_import, division, print_function, | ||
unicode_literals) | ||
|
||
import numpy as np | ||
from nose.tools import assert_true | ||
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(): | ||
# SF bug 2852168 | ||
fig = plt.figure() | ||
x = np.linspace(0,2*np.pi,100) | ||
x = np.linspace(0, 2*np.pi, 100) | ||
y = 2*np.sin(x) | ||
ax = fig.add_subplot(1,1,1) | ||
ax = fig.add_subplot(1, 1, 1) | ||
ax.set_title('centered spines') | ||
ax.plot(x,y) | ||
ax.spines['right'].set_position(('axes',0.1)) | ||
ax.plot(x, y) | ||
ax.spines['right'].set_position(('axes', 0.1)) | ||
ax.yaxis.set_ticks_position('right') | ||
ax.spines['top'].set_position(('axes',0.25)) | ||
ax.spines['top'].set_position(('axes', 0.25)) | ||
ax.xaxis.set_ticks_position('top') | ||
ax.spines['left'].set_color('none') | ||
ax.spines['bottom'].set_color('none') | ||
|
||
|
||
@image_comparison(baseline_images=['spines_data_positions']) | ||
def test_spines_data_positions(): | ||
fig = plt.figure() | ||
ax = fig.add_subplot(1,1,1) | ||
ax = fig.add_subplot(1, 1, 1) | ||
ax.spines['left'].set_position(('data', -1.5)) | ||
ax.spines['top'].set_position(('data', 0.5)) | ||
ax.spines['right'].set_position(('data', -0.5)) | ||
ax.spines['bottom'].set_position('zero') | ||
ax.set_xlim([-2,2]) | ||
ax.set_ylim([-2,2]) | ||
ax.set_xlim([-2, 2]) | ||
ax.set_ylim([-2, 2]) | ||
|
||
|
||
@image_comparison(baseline_images=['spines_capstyle']) | ||
def test_spines_capstyle(): | ||
# issue 2542 | ||
plt.rc('axes', linewidth=20) | ||
fig = plt.figure() | ||
ax = fig.add_subplot(1,1,1) | ||
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() | ||
# replace with assert_less if >python2.6 | ||
assert_true(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() | ||
# replace with assert_less if >python2.6 | ||
assert_true(ax.xaxis.label.get_position()[1] < spinebbox.ymin, | ||
"X-Axis label not below the spine") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make more sense to just throw the bounding box of the spine and the axes in to the bboxes list and let the
union
call take care of this logic?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, @tacaswell, I think that makes more sense. I'll update to do just that.