diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 59209fc7755c..5573abbf32ce 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -22,6 +22,7 @@ import matplotlib.colors as mcolors import matplotlib.cm as cm import matplotlib.cbook as cbook +from matplotlib import patches as mpatches # For clarity, names from _image are given explicitly in this module: import matplotlib._image as _image @@ -299,6 +300,8 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0, `trans` is the affine transformation from the image to pixel space. """ + from matplotlib import axes as maxes + if A is None: raise RuntimeError('You must first set the image' ' array or the image attribute') @@ -336,11 +339,15 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0, -clipped_bbox.y0) .scale(magnification, magnification)) - # So that the image is aligned with the edge of the axes, we want - # to round up the output width to the next integer. This also - # means scaling the transform just slightly to account for the - # extra subpixel. - if (t.is_affine and round_to_pixel_border and + # So that the image is aligned with the edge of the axes, we + # want to round up the output width to the next integer. This + # also means scaling the transform just slightly to account + # for the extra subpixel. This is only required for regular + # rectangular axes where the edges are pixel-snapped. For + # non-rectangular axes, this refinement isn't required. + if (round_to_pixel_border and + t.is_affine and + isinstance(self.axes, mpatches.Rectangle) and (out_width_base % 1.0 != 0.0 or out_height_base % 1.0 != 0.0)): out_width = int(ceil(out_width_base) + 1) diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axes_grid/imagegrid_cbar_mode.png b/lib/mpl_toolkits/tests/baseline_images/test_axes_grid/imagegrid_cbar_mode.png index e1a87370ff93..e0c408741417 100644 Binary files a/lib/mpl_toolkits/tests/baseline_images/test_axes_grid/imagegrid_cbar_mode.png and b/lib/mpl_toolkits/tests/baseline_images/test_axes_grid/imagegrid_cbar_mode.png differ