Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c88fedb

Browse filesBrowse files
committed
Implementing shareaxis.
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.
1 parent c85b029 commit c88fedb
Copy full SHA for c88fedb

File tree

Expand file treeCollapse file tree

12 files changed

+539
-63
lines changed
Filter options
Expand file treeCollapse file tree

12 files changed

+539
-63
lines changed

‎doc/api/api_changes/2017-12-06-KL.rst

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Change return value of Axes.get_shared_[x,y,z]_axes()
2+
-----------------------------------------------
3+
4+
The method `matplotlib.Axes.get_shared_x_axes` (and y and z) used to return `~.cbook.Grouper` objects.
5+
Now it returns a `~.weakref.WeakSet` object.
6+
7+
Workarounds:
8+
* If the intention is to get siblings as previous then the WeakSet contains all the siblings.
9+
An example::
10+
11+
sharedx = ax.get_shared_x_axes().get_siblings()
12+
# is now
13+
sharedx = list(ax.get_shared_x_axes())
14+
15+
* If the intention was to use `join` then there is a new share axes method. An example::
16+
17+
ax1.get_shared_x_axes().join(ax1, ax2)
18+
# is now
19+
ax1.share_x_axes(ax2)
20+
21+
* If the intention was to check if two elements are in the same group then use the `in` operator. An example::
22+
23+
ax1.get_shared_x_axes().joined(ax1, ax2)
24+
# is now
25+
ax2 in ax1.get_shared_x_axes()
26+
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Share and unshare `axes` after creation
2+
---------------------------------------
3+
4+
`~.Axes` have `~.Axes.unshare_x_axes`, `~.Axes.unshare_y_axes`, `~.Axes.unshare_z_axes` and `~.Axes.unshare_axes` methods to unshare axes.
5+
Similiar there are `~.Axes.share_x_axes`, `~.Axes.share_y_axes`, `~.Axes.share_z_axes` and `~.Axes.share_axes` methods to share axes.
6+
7+
Unshare an axis will decouple the viewlimits for further changes.
8+
Share an axis will couple the viewlimits.
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
============================================
3+
Parametric Curve with Share and Unshare Axes
4+
============================================
5+
6+
This example demonstrates plotting a parametric curve in 3D,
7+
and how to share and unshare 3D plot axes.
8+
"""
9+
import matplotlib as mpl
10+
from mpl_toolkits.mplot3d import Axes3D
11+
import numpy as np
12+
import matplotlib.pyplot as plt
13+
14+
mpl.rcParams['legend.fontsize'] = 10
15+
16+
# Prepare arrays x, y, z
17+
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
18+
z = np.linspace(-2, 2, 100)
19+
r = z ** 2 + 1
20+
x = r * np.sin(theta)
21+
y = r * np.cos(theta)
22+
23+
fig = plt.figure()
24+
ax = fig.add_subplot(311, projection='3d')
25+
26+
ax.plot(x, y, z, label='parametric curve')
27+
ax.legend()
28+
29+
ax1 = fig.add_subplot(312)
30+
ax1.plot(range(10))
31+
ax1.share_axes(ax)
32+
33+
ax2 = fig.add_subplot(313, projection='3d', sharex=ax)
34+
ax2.plot(x, y, z)
35+
36+
ax2.unshare_x_axes(ax)
37+
ax2.share_z_axes(ax)
38+
39+
plt.show()
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
======================
3+
Unshare and share axis
4+
======================
5+
6+
The example shows how to share and unshare axes after they are created.
7+
"""
8+
9+
import matplotlib.pyplot as plt
10+
import numpy as np
11+
12+
t = np.arange(0.01, 5.0, 0.01)
13+
s1 = np.sin(2 * np.pi * t)
14+
s2 = np.exp(-t)
15+
s3 = np.sin(4 * np.pi * t)
16+
17+
ax1 = plt.subplot(311)
18+
plt.plot(t, s1)
19+
20+
ax2 = plt.subplot(312)
21+
plt.plot(t, s2)
22+
23+
ax3 = plt.subplot(313)
24+
plt.plot(t, s3)
25+
26+
ax1.share_x_axes(ax2)
27+
ax1.share_y_axes(ax2)
28+
29+
# Share both axes.
30+
ax3.share_axes(ax1)
31+
plt.xlim(0.01, 5.0)
32+
33+
ax3.unshare_y_axes()
34+
ax2.unshare_x_axes()
35+
36+
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.