-
-
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
Changes from 1 commit
e157edc
df83b52
6817e54
fec3007
4febb39
765ce77
8d3acc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Sharexy use Weakref instead of cbook.Grouper Add a share/unshare function to share/unshare both x,y,z axis remove() unshare axes successfully. Revert to Grouper. But now grouper remove will also remove from other sets. unshare will also remove parent/master axes. unshare also remove parent axes in the orphan axes. Adding unshare and share tests. Add what is new. Adding unshare axis demo. Revert "Revert to Grouper. But now grouper remove will also remove from other sets." Converting Weakset to list and back during pickle. Adding pickle test. Update tests to use Weakset backend. Add example of how to share 3D plot. Add an API breakage message. change twinx, twiny to use the new share api. Adding an is sharing axes method. Fix overline in example too short. Use the new is_sharing_[x,y]_axes when appropriate update tests to use is sharing axes methods Simplify share and unsharing code to one. remove crufts. Change quotation marks. Update descriptions. Update docs. Unshare axes if related. Sharing will implicit set adjustable to datalim. Copy major and minor when unshare axes. If unshare a parent axes its children will copy a new major minor.
- Loading branch information
There are no files selected for viewing
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() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Share and unshare `axes` after creation | ||
--------------------------------------- | ||
|
||
`~.Axes` have `~.Axes.unshare_x_axes`, `~.Axes.unshare_y_axes`, `~.Axes.unshare_z_axes` and `~.Axes.unshare_axes` methods to unshare axes. | ||
Similiar there are `~.Axes.share_x_axes`, `~.Axes.share_y_axes`, `~.Axes.share_z_axes` and `~.Axes.share_axes` methods to share axes. | ||
|
||
Unshare an axis will decouple the viewlimits for further changes. | ||
Share an axis will couple the viewlimits. |
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(ax) | ||
ax2.share_z_axes(ax) | ||
|
||
plt.show() |
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. hm... no comment. |
||
|
||
plt.show() |
Uh oh!
There was an error while loading. Please reload this page.