8000 Merge pull request #14809 from anntzer/connectionpatchcalls · matplotlib/matplotlib@c7ab2be · GitHub
[go: up one dir, main page]

Skip to content

Commit c7ab2be

Browse files
authored
Merge pull request #14809 from anntzer/connectionpatchcalls
Clearer calls to ConnectionPatch.
2 parents 61f215c + e0b2bcc commit c7ab2be

File tree

3 files changed

+22
-28
lines changed

3 files changed

+22
-28
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, 8000 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
@@ -549,12 +549,11 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
549549
if self.yaxis.get_inverted():
550550
ey = 1 - ey
551551
xy_data = x + ex * width, y + ey * height
552-
p = mpatches.ConnectionPatch(xy_inset_ax, xy_data,
553-
coordsA='axes fraction',
554-
coordsB='data',
555-
axesA=inset_ax, axesB=self,
556-
arrowstyle="-", zorder=zorder,
557-
edgecolor=edgecolor, alpha=alpha)
552+
p = mpatches.ConnectionPatch(
553+
xyA=xy_inset_ax, coordsA=inset_ax.transAxes,
554+
xyB=xy_data, coordsB=self.transData,
555+
arrowstyle="-", zorder=zorder,
556+
edgecolor=edgecolor, alpha=alpha)
558557
connects.append(p)
559558
self.add_patch(p)
560559

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

613611
xlim = inset_ax.get_xlim()
614612
ylim = inset_ax.get_ylim()
615613
rect = (xlim[0], ylim[0], xlim[1] - xlim[0], ylim[1] - ylim[0])
616-
rectpatch, connects = self.indicate_inset(
617-
rect, inset_ax, **kwargs
618-
)
619-
620-
return rectpatch, connects
614+
return self.indicate_inset(rect, inset_ax, **kwargs)
621615

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

0 commit comments

Comments
 (0)
0