diff --git a/examples/pie_and_polar_charts/bar_of_pie.py b/examples/pie_and_polar_charts/bar_of_pie.py index 637092d1b8e3..bf5c438c176a 100644 --- a/examples/pie_and_polar_charts/bar_of_pie.py +++ b/examples/pie_and_polar_charts/bar_of_pie.py @@ -15,7 +15,7 @@ import numpy as np # make figure and assign axis objects -fig = plt.figure(figsize=(9, 5.0625)) +fig = plt.figure(figsize=(9, 5)) ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122) fig.subplots_adjust(wspace=0) @@ -59,8 +59,8 @@ # draw top connecting line x = r * np.cos(np.pi / 180 * theta2) + center[0] y = np.sin(np.pi / 180 * theta2) + center[1] -con = ConnectionPatch(xyA=(- width / 2, bar_height), xyB=(x, y), - coordsA="data", coordsB="data", axesA=ax2, axesB=ax1) +con = ConnectionPatch(xyA=(-width / 2, bar_height), coordsA=ax2.transData, + xyB=(x, y), coordsB=ax1.transData) con.set_color([0, 0, 0]) con.set_linewidth(4) ax2.add_artist(con) @@ -68,8 +68,8 @@ # draw bottom connecting line x = r * np.cos(np.pi / 180 * theta1) + center[0] y = np.sin(np.pi / 180 * theta1) + center[1] -con = ConnectionPatch(xyA=(- width / 2, 0), xyB=(x, y), coordsA="data", - coordsB="data", axesA=ax2, axesB=ax1) +con = ConnectionPatch(xyA=(-width / 2, 0), coordsA=ax2.transData, + xyB=(x, y), coordsB=ax1.transData) con.set_color([0, 0, 0]) ax2.add_artist(con) con.set_linewidth(4) diff --git a/examples/userdemo/connect_simple01.py b/examples/userdemo/connect_simple01.py index 7aea4d717182..20f84e1830b2 100644 --- a/examples/userdemo/connect_simple01.py +++ b/examples/userdemo/connect_simple01.py @@ -6,6 +6,7 @@ A `ConnectionPatch` can be used to draw a line (possibly with arrow head) between points defined in different coordinate systems and/or axes. """ + from matplotlib.patches import ConnectionPatch import matplotlib.pyplot as plt @@ -26,21 +27,20 @@ # Draw an arrow between the same point in data coordinates, # but in different axes. xy = (0.3, 0.2) -coordsA = "data" -coordsB = "data" -con = ConnectionPatch(xyA=xy, xyB=xy, coordsA=coordsA, coordsB=coordsB, - axesA=ax2, axesB=ax1, - arrowstyle="->", shrinkB=5) +con = ConnectionPatch( + xyA=xy, coordsA=ax2.transData, + xyB=xy, coordsB=ax1.transData, + arrowstyle="->", shrinkB=5) ax2.add_artist(con) # Draw a line between the different points, defined in different coordinate # systems. -xyA = (0.6, 1.0) # in axes coordinates -xyB = (0.0, 0.2) # x in axes coordinates, y in data coordinates -coordsA = "axes fraction" -coordsB = ax2.get_yaxis_transform() -con = ConnectionPatch(xyA=xyA, xyB=xyB, coordsA=coordsA, coordsB=coordsB, - arrowstyle="-") +con = ConnectionPatch( + # in axes coordinates + xyA=(0.6, 1.0), coordsA=ax2.transAxes, + # x in axes coordinates, y in data coordinates + xyB=(0.0, 0.2), coordsB=ax2.get_yaxis_transform(), + arrowstyle="-") ax2.add_artist(con) ax1.set_xlim(0, 1) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index db432cf3b04a..6fec612edbb8 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -548,12 +548,11 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None, if self.yaxis.get_inverted(): ey = 1 - ey xy_data = x + ex * width, y + ey * height - p = mpatches.ConnectionPatch(xy_inset_ax, xy_data, - coordsA='axes fraction', - coordsB='data', - axesA=inset_ax, axesB=self, - arrowstyle="-", zorder=zorder, - edgecolor=edgecolor, alpha=alpha) + p = mpatches.ConnectionPatch( + xyA=xy_inset_ax, coordsA=inset_ax.transAxes, + xyB=xy_data, coordsB=self.transData, + arrowstyle="-", zorder=zorder, + edgecolor=edgecolor, alpha=alpha) connects.append(p) self.add_patch(p) @@ -606,17 +605,12 @@ def indicate_inset_zoom(self, inset_ax, **kwargs): Two are set with visibility to *False*, but the user can set the visibility to *True* if the automatic choice is not deemed correct. - """ xlim = inset_ax.get_xlim() ylim = inset_ax.get_ylim() rect = (xlim[0], ylim[0], xlim[1] - xlim[0], ylim[1] - ylim[0]) - rectpatch, connects = self.indicate_inset( - rect, inset_ax, **kwargs - ) - - return rectpatch, connects + return self.indicate_inset(rect, inset_ax, **kwargs) @docstring.dedent_interpd def secondary_xaxis(self, location, *, functions=None, **kwargs): diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 6458487a6eb4..f474a8f7c991 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -4240,10 +4240,8 @@ def __init__(self, xyA, xyB, coordsA, coordsB=None, """ Connect point *xyA* in *coordsA* with point *xyB* in *coordsB* - Valid keys are - =============== ====================================================== Key Description =============== ====================================================== @@ -4259,7 +4257,6 @@ def __init__(self, xyA, xyB, coordsA, coordsB=None, ? any key for :class:`matplotlib.patches.PathPatch` =============== ====================================================== - *coordsA* and *coordsB* are strings that indicate the coordinates of *xyA* and *xyB*.