-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Share and unshare axes after creation. #9923
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e157edc
Implementing shareaxis.
lkjell df83b52
Fix test related to sharing
lkjell 6817e54
Update api changes.
lkjell fec3007
Simplify unshare code.
lkjell 4febb39
Simplify share code.
lkjell 765ce77
Fix example unshare code.
lkjell 8d3acc3
Fix rebase error
lkjell 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Change return value of Axes.get_shared_[x,y,z]_axes() | ||
----------------------------------------------------- | ||
|
||
The method `matplotlib.Axes.get_shared_x_axes` (and y and z) used to return `~.cbook.Grouper` objects. | ||
Now it returns a `~.weakref.WeakSet` object. | ||
|
||
Workarounds: | ||
* If the intention is to get siblings as previous then the WeakSet contains all the siblings. | ||
An example:: | ||
|
||
sharedx = ax.get_shared_x_axes().get_siblings() | ||
# is now | ||
sharedx = list(ax.get_shared_x_axes()) | ||
|
||
* If the intention was to use `join` then there is a new share axes method. An example:: | ||
|
||
ax1.get_shared_x_axes().join(ax1, ax2) | ||
# is now | ||
ax1.share_x_axes(ax2) | ||
|
||
* If the intention was to check if two elements are in the same group then use the `in` operator. An example:: | ||
|
||
ax1.get_shared_x_axes().joined(ax1, ax2) | ||
# is now | ||
ax2 in ax1.get_shared_x_axes() | ||
|
8 changes: 8 additions & 0 deletions
8
doc/api/next_api_changes/remove_old_share_axes_after_creation.rst
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,8 @@ | ||
Remove share through `matplotlib.Axes.get_shared_{x,y,z}_axes` | ||
-------------------------------------------------------------- | ||
|
||
Previously when different axes are created with different parent/master axes, | ||
the share would still be symmetric and transitive if an unconventional | ||
method through `matplotlib.Axes.get_shared_x_axes` | ||
is used to share the axes after creation. With the new sharing mechanism | ||
this is no longer possible. |
12 changes: 12 additions & 0 deletions
12
doc/users/next_whats_new/2017-12-05_share_unshare_axes_after_creation.rst
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,12 @@ | ||
Share and unshare `axes` after creation | ||
--------------------------------------- | ||
|
||
`matplotlib.axes.Axes` have `matplotlib.axes.Axes.unshare_x_axes`, | ||
`matplotlib.axes.Axes.unshare_y_axes`, `matplotlib.axes.Axes.unshare_z_axes` | ||
and `matplotlib.axes.Axes.unshare_axes` methods to unshare axes. | ||
Similiar there are `matplotlib.axes.Axes.share_x_axes`, | ||
`matplotlib.axes.Axes.share_y_axes`, `matplotlib.axes.Axes.share_z_axes` and | ||
`matplotlib.axes.Axes.share_axes` methods to share axes. | ||
|
||
Unshare an axis will decouple the viewlimits for further changes. | ||
Share an axis will couple the viewlimits. |
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,39 @@ | ||
""" | ||
============================================ | ||
Parametric Curve with Share and Unshare Axes | ||
============================================ | ||
|
||
This example demonstrates plotting a parametric curve in 3D, | ||
and how to share and unshare 3D plot axes. | ||
""" | ||
import matplotlib as mpl | ||
from mpl_toolkits.mplot3d import Axes3D | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
mpl.rcParams['legend.fontsize'] = 10 | ||
|
||
# Prepare arrays x, y, z | ||
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100) | ||
z = np.linspace(-2, 2, 100) | ||
r = z ** 2 + 1 | ||
x = r * np.sin(theta) | ||
y = r * np.cos(theta) | ||
|
||
fig = plt.figure() | ||
ax = fig.add_subplot(311, projection='3d') | ||
|
||
ax.plot(x, y, z, label='parametric curve') | ||
ax.legend() | ||
|
||
ax1 = fig.add_subplot(312) | ||
ax1.plot(range(10)) | ||
ax1.share_axes(ax) | ||
|
||
ax2 = fig.add_subplot(313, projection='3d', sharex=ax) | ||
ax2.plot(x, y, z) | ||
|
||
ax2.unshare_x_axes() | ||
ax2.share_z_axes(ax) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
====================== | ||
Unshare and share axis | ||
====================== | ||
|
||
The example shows how to share and unshare axes after they are created. | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
t = np.arange(0.01, 5.0, 0.01) | ||
s1 = np.sin(2 * np.pi * t) | ||
s2 = np.exp(-t) | ||
s3 = np.sin(4 * np.pi * t) | ||
|
||
ax1 = plt.subplot(311) | ||
plt.plot(t, s1) | ||
|
||
ax2 = plt.subplot(312) | ||
plt.plot(t, s2) | ||
|
||
ax3 = plt.subplot(313) | ||
plt.plot(t, s3) | ||
|
||
ax1.share_x_axes(ax2) | ||
ax1.share_y_axes(ax2) | ||
|
||
# Share both axes. | ||
ax3.share_axes(ax1) | ||
plt.xlim(0.01, 5.0) | ||
|
||
ax3.unshare_y_axes() | ||
ax2.unshare_x_axes() | ||
|
||
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
Oops, something went wrong.
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.
I didn't try to run this, but its hard to imagine this actually demos anything in a non-interactive session.
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.
You do not create share as usual by setting a share parent axes. Sharing is set after the creation of the axes.
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.
I think demos should be readily readable by users since they are one of the primary ways we document Matplotlib. I find this demo is very cryptic. Why are you un-sharing? Just to show that these functions exist? What effect does this have on the example? The description of the demo should state the usual way of sharing, and this alternate way.
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.
hm... no comment.