8000 Clearer calls to ConnectionPatch. · matplotlib/matplotlib@e0b2bcc · GitHub
[go: up one dir, main page]

Skip to content

Commit e0b2bcc

Browse files
committed
Clearer calls to ConnectionPatch.
... by moving the transform next to the xy values, and by using transforms rather than splitting the transform in two separate keyword arguments (axesA and coordsA).
1 parent 2bc6721 commit e0b2bcc

File tree

4 files changed

+22
-31
lines changed

4 files changed

+22
-31
lines changed

examples/pie_and_polar_charts/bar_of_pie.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import numpy as np
1616

1717
# make figure and assign axis objects
18-
fig = plt.figure(figsize=(9, 5.0625))
18+
fig = plt.figure(figsize=(9, 5))
1919
ax1 = fig.add_subplot(121)
2020
ax2 = fig.add_subplot(122)
2121
fig.subplots_adjust(wspace=0)
@@ -59,17 +59,17 @@
5959
# draw top connecting line
6060
x = r * np.cos(np.pi / 180 * theta2) + center[0]
6161
y = np.sin(np.pi / 180 * theta2) + center[1]
62-
con = ConnectionPatch(xyA=(- width / 2, bar_height), xyB=(x, y),
63-
coordsA="data", coordsB="data", axesA=ax2, axesB=ax1)
62+
con = ConnectionPatch(xyA=(-width / 2, bar_height), coordsA=ax2.transData,
63+
xyB=(x, y), coordsB=ax1.transData)
6464
con.set_color([0, 0, 0])
6565
con.set_linewidth(4)
6666
ax2.add_artist(con)
6767

6868
# draw bottom connecting line
6969
x = r * np.cos(np.pi / 180 * theta1) + center[0]
7070
y = np.sin(np.pi / 180 * theta1) + center[1]
71-
con = ConnectionPatch(xyA=(- width / 2, 0), xyB=(x, y), coordsA="data",
72-
coordsB="data", axesA=ax2, axesB=ax1)
71+
con = ConnectionPatch(xyA=(-width / 2, 0), coordsA=ax2.transData,
72+
xyB=(x, y), coordsB=ax1.transData)
7373
con.set_color([0, 0, 0])
7474
ax2.add_artist(con)
7575
con.set_linewidth(4)

examples/userdemo/connect_simple01.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
A `ConnectionPatch` can be used to draw a line (possibly with arrow head)
77
between points defined in different coordinate systems and/or axes.
88
"""
9+
910
from matplotlib.patches import ConnectionPatch
1011
import matplotlib.pyplot as plt
1112

@@ -26,21 +27,20 @@
2627
# Draw an arrow between the same point in data coordinates,
2728
# but in different axes.
2829
xy = (0.3, 0.2)
29-
coordsA = "data"
30-
coordsB = "data"
31-
con = ConnectionPatch(xyA=xy, xyB=xy, coordsA=coordsA, coordsB=coordsB,
32-
axesA=ax2, axesB=ax1,
33-
arrowstyle="->", shrinkB=5)
30+
con = ConnectionPatch(
31+
xyA=xy, coordsA=ax2.transData,
32+
xyB=xy, coordsB=ax1.transData,
33+
arrowstyle="->", shrinkB=5)
3434
ax2.add_artist(con)
3535

3636
# Draw a line between the different points, defined in different coordinate
3737
# systems.
38-
xyA = (0.6, 1.0) # in axes coordinates
39-
xyB = (0.0, 0.2) # x in axes coordinates, y in data coordinates
40-
coordsA = "axes fraction"
41-
coordsB = ax2.get_yaxis_transform()
42-
con = ConnectionPatch(xyA=xyA, xyB=xyB, coordsA=coordsA, coordsB=coordsB,
43-
arrowstyle="-")
38+
con = ConnectionPatch(
39+
# in axes coordinates
40+
xyA=(0.6, 1.0), coordsA=ax2.transAxes,
41+
# x in axes coordinates, y in data coordinates
42+
xyB=(0.0, 0.2), coordsB=ax2.get_yaxis_transform(),
43+
arrowstyle="-")
4444
ax2.add_artist(con)
4545

4646
ax1.set_xlim(0, 1)

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,11 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
548548
if self.yaxis.get_inverted():
549549
ey = 1 - ey
550550
xy_data = x + ex * width, y + ey * height
551-
p = mpatches.ConnectionPatch(xy_inset_ax, xy_data,
552-
coordsA='axes fraction',
553-
coordsB='data',
554-
axesA=inset_ax, axesB=self,
555-
arrowstyle="-", zorder=zorder,
556-
edgecolor=edgecolor, alpha=alpha)
551+
p = mpatches.ConnectionPatch(
552+
xyA=xy_inset_ax, coordsA=inset_ax.transAxes,
553+
xyB=xy_data, coordsB=self.transData,
554+
arrowstyle="-", zorder=zorder,
555+
edgecolor=edgecolor, alpha=alpha)
557556
connects.append(p)
558557
self.add_patch(p)
559558

@@ -606,17 +605,12 @@ def indicate_inset_zoom(self, inset_ax, **kwargs):
606605
Two are set with visibility to *False*, but the user can
607606
set the visibility to *True* if the automatic choice is not deemed
608607
correct.
609-
610608
"""
611609

612610
xlim = inset_ax.get_xlim()
613611
ylim = inset_ax.get_ylim()
614612
rect = (xlim[0], ylim[0], xlim[1] - xlim[0], ylim[1] - ylim[0])
615-
rectpatch, connects = self.indicate_inset(
616-
rect, inset_ax, **kwargs
617-
)
618-
619-
return rectpatch, connects
613+
return self.indicate_inset(rect, inset_ax, **kwargs)
620614

621615
@docstring.dedent_interpd
622616
def secondary_xaxis(self, location, *, functions=None, **kwargs):

lib/matplotlib/patches.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4240,10 +4240,8 @@ def __init__(self, xyA, xyB, coordsA, coordsB=None,
42404240
"""
42414241
Connect point *xyA* in *coordsA* with point *xyB* in *coordsB*
42424242
4243-
42444243
Valid keys are
42454244
4246-
42474245
=============== ======================================================
42484246
Key Description
42494247
=============== ======================================================
@@ -4259,7 +4257,6 @@ def __init__(self, xyA, xyB, coordsA, coordsB=None,
42594257
? any key for :class:`matplotlib.patches.PathPatch`
42604258
=============== ======================================================
42614259
4262-
42634260
*coordsA* and *coordsB* are strings that indicate the
42644261
coordinates of *xyA* and *xyB*.
42654262

0 commit comments

Comments
 (0)
0