-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Doc: spines arrows example #17180
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
ImportanceOfBeingErnest
merged 1 commit into
matplotlib:master
from
ImportanceOfBeingErnest:doc-spinesarrows
Apr 18, 2020
Merged
Doc: spines arrows example #17180
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
=========================== | ||
Centered spines with arrows | ||
=========================== | ||
|
||
This example shows a way to draw a "math textbook" style plot, where the | ||
spines ("axes lines") are drawn at ``x = 0`` and ``y = 0``, and have arrows at | ||
their ends. | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
|
||
fig, ax = plt.subplots() | ||
# Move the left and bottom spines to x = 0 and y = 0, respectively. | ||
ax.spines["left"].set_position(("data", 0)) | ||
ax.spines["bottom"].set_position(("data", 0)) | ||
# Hide the top and right spines. | ||
ax.spines["top"].set_visible(False) | ||
ax.spines["right"].set_visible(False) | ||
|
||
# Draw arrows (as black triangles: ">k"/"^k") at the end of the axes. In each | ||
# case, one of the coordinates (0) is a data coordinate (i.e., y = 0 or x = 0, | ||
# respectively) and the other one (1) is an axes coordinate (i.e., at the very | ||
# right/top of the axes). Also, disable clipping (clip_on=False) as the marker | ||
# actually spills out of the axes. | ||
ax.plot(1, 0, ">k", transform=ax.get_yaxis_transform(), clip_on=False) | ||
ax.plot(0, 1, "^k", transform=ax.get_xaxis_transform(), clip_on=False) | ||
|
||
# Some sample data. | ||
x = np.linspace(-0.5, 1., 100) | ||
ax.plot(x, np.sin(x*np.pi)) | ||
|
||
plt.show() |
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
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.
Does something like this add arrows on the other ends of the axes, as well? (For when axes are lines instead of only rays)
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.
... Aesthetically, arrows on both ends of each axis are probably what most math teachers are looking for