From 755cb2a41f9c642f07e6590da4ddec0c0d2b960e Mon Sep 17 00:00:00 2001 From: Benjamin Root Date: Thu, 23 Jul 2020 15:46:10 -0400 Subject: [PATCH] Backport PR #18038: FIX: use internal _set_postion, not external --- lib/mpl_toolkits/mplot3d/axes3d.py | 2 +- lib/mpl_toolkits/tests/test_mplot3d.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index ebf03f7bf20f..83f63c2e5121 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -410,7 +410,7 @@ def apply_aspect(self, position=None): box_aspect = 1 pb = position.frozen() pb1 = pb.shrunk_to_aspect(box_aspect, pb, fig_aspect) - self.set_position(pb1.anchored(self.get_anchor(), pb), 'active') + self._set_position(pb1.anchored(self.get_anchor(), pb), 'active') @artist.allow_rasterization def draw(self, renderer): diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index 37532335e38d..9973071a7013 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -1008,3 +1008,19 @@ def test_equal_box_aspect(): ax.set_zlim3d(XYZlim) ax.axis('off') ax.set_box_aspect((1, 1, 1)) + + +def test_colorbar_pos(): + num_plots = 2 + fig, axs = plt.subplots(1, num_plots, figsize=(4, 5), + constrained_layout=True, + subplot_kw={'projection': '3d'}) + for ax in axs: + p_tri = ax.plot_trisurf(np.random.randn(5), np.random.randn(5), + np.random.randn(5)) + + cbar = plt.colorbar(p_tri, ax=axs, orientation='horizontal') + + fig.canvas.draw() + # check that actually on the bottom + assert cbar.ax.get_position().extents[1] < 0.2