diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 6722003751d0..fd5380d2caab 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -4063,7 +4063,7 @@ def __init__(self, posA=None, posB=None, def set_dpi_cor(self, dpi_cor): """ dpi_cor is currently used for linewidth-related things and - shrink factor. Mutation scale is not affected by this. + shrink factor. Mutation scale is affected by this. """ self._dpi_cor = dpi_cor @@ -4072,7 +4072,7 @@ def set_dpi_cor(self, dpi_cor): def get_dpi_cor(self): """ dpi_cor is currently used for linewidth-related things and - shrink factor. Mutation scale is not affected by this. + shrink factor. Mutation scale is affected by this. """ return self._dpi_cor @@ -4224,15 +4224,16 @@ def get_path_in_displaycoord(self): patchB=self.patchB, shrinkA=self.shrinkA * dpi_cor, shrinkB=self.shrinkB * dpi_cor - ) + ) else: _path = self.get_transform().transform_path(self._path_original) - _path, fillable = self.get_arrowstyle()(_path, - self.get_mutation_scale(), - self.get_linewidth() * dpi_cor, - self.get_mutation_aspect() - ) + _path, fillable = self.get_arrowstyle()( + _path, + self.get_mutation_scale() * dpi_cor, + self.get_linewidth() * dpi_cor, + self.get_mutation_aspect() + ) #if not fillable: # self._fill = False @@ -4542,13 +4543,14 @@ def get_path_in_displaycoord(self): patchB=self.patchB, shrinkA=self.shrinkA * dpi_cor, shrinkB=self.shrinkB * dpi_cor - ) - - _path, fillable = self.get_arrowstyle()(_path, - self.get_mutation_scale(), - self.get_linewidth() * dpi_cor, - self.get_mutation_aspect() - ) + ) + + _path, fillable = self.get_arrowstyle()( + _path, + self.get_mutation_scale() * dpi_cor, + self.get_linewidth() * dpi_cor, + self.get_mutation_aspect() + ) return _path, fillable diff --git a/lib/matplotlib/tests/baseline_images/test_arrow_patches/fancyarrow_dpi_cor_100dpi.png b/lib/matplotlib/tests/baseline_images/test_arrow_patches/fancyarrow_dpi_cor_100dpi.png new file mode 100644 index 000000000000..abd1bbe9b2df Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_arrow_patches/fancyarrow_dpi_cor_100dpi.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_arrow_patches/fancyarrow_dpi_cor_200dpi.png b/lib/matplotlib/tests/baseline_images/test_arrow_patches/fancyarrow_dpi_cor_200dpi.png new file mode 100644 index 000000000000..c8efdd75e9e3 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_arrow_patches/fancyarrow_dpi_cor_200dpi.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/polar_axes.png b/lib/matplotlib/tests/baseline_images/test_axes/polar_axes.png index b99565824582..d74b58e424fb 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/polar_axes.png and b/lib/matplotlib/tests/baseline_images/test_axes/polar_axes.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/polar_coords.png b/lib/matplotlib/tests/baseline_images/test_axes/polar_coords.png index a91c028fc8a3..106b8fdb1cf8 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/polar_coords.png and b/lib/matplotlib/tests/baseline_images/test_axes/polar_coords.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_colormap.png b/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_colormap.png index 76563093dff4..5e342ee0bb46 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_colormap.png and b/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_colormap.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_linewidth.png b/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_linewidth.png index a7cc01d7ba80..58653bcaaae6 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_linewidth.png and b/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_linewidth.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_masks_and_nans.png b/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_masks_and_nans.png index 23e4657ca1a2..a87c95aa753f 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_masks_and_nans.png and b/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_masks_and_nans.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_startpoints.png b/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_startpoints.png index b7cd05eea3ec..734179dc3a7d 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_startpoints.png and b/lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_startpoints.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_transforms/pre_transform_data.png b/lib/matplotlib/tests/baseline_images/test_transforms/pre_transform_data.png index 5cac1cc404bf..24c69eb926b5 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_transforms/pre_transform_data.png and b/lib/matplotlib/tests/baseline_images/test_transforms/pre_transform_data.png differ diff --git a/lib/matplotlib/tests/test_arrow_patches.py b/lib/matplotlib/tests/test_arrow_patches.py index 0a624d0e2801..c15389ee0f51 100644 --- a/lib/matplotlib/tests/test_arrow_patches.py +++ b/lib/matplotlib/tests/test_arrow_patches.py @@ -5,7 +5,7 @@ import matplotlib.pyplot as plt from matplotlib.testing.decorators import image_comparison -import matplotlib +import matplotlib.patches as mpatches def draw_arrow(ax, t, r): @@ -18,7 +18,7 @@ def draw_arrow(ax, t, r): def test_fancyarrow(): # Added 0 to test division by zero error described in issue 3930 r = [0.4, 0.3, 0.2, 0.1, 0] - t = ["fancy", "simple", matplotlib.patches.ArrowStyle.Fancy()] + t = ["fancy", "simple", mpatches.ArrowStyle.Fancy()] fig, axes = plt.subplots(len(t), len(r), squeeze=False, subplot_kw=dict(aspect=True), @@ -34,7 +34,7 @@ def test_fancyarrow(): @image_comparison(baseline_images=['boxarrow_test_image'], extensions=['png']) def test_boxarrow(): - styles = matplotlib.patches.BoxStyle.get_styles() + styles = mpatches.BoxStyle.get_styles() n = len(styles) spacing = 1.2 @@ -52,6 +52,51 @@ def test_boxarrow(): bbox=dict(boxstyle=stylename, fc="w", ec="k")) +def __prepare_fancyarrow_dpi_cor_test(): + """ + Convenience function that prepares and returns a FancyArrowPatch. It aims + at being used to test that the size of the arrow head does not depend on + the DPI value of the exported picture. + + NB: this function *is not* a test in itself! + """ + fig2 = plt.figure("fancyarrow_dpi_cor_test", figsize=(4, 3), dpi=50) + ax = fig2.add_subplot(111) + ax.set_xlim([0, 1]) + ax.set_ylim([0, 1]) + ax.add_patch(mpatches.FancyArrowPatch(posA=(0.3, 0.4), posB=(0.8, 0.6), + lw=3, arrowstyle=u'->', + mutation_scale=100)) + return fig2 + + +@image_comparison(baseline_images=['fancyarrow_dpi_cor_100dpi'], + remove_text=True, extensions=['png'], + savefig_kwarg=dict(dpi=100)) +def test_fancyarrow_dpi_cor_100dpi(): + """ + Check the export of a FancyArrowPatch @ 100 DPI. FancyArrowPatch is + instantiated through a dedicated function because another similar test + checks a similar export but with a different DPI value. + + Remark: test only a rasterized format. + """ + + __prepare_fancyarrow_dpi_cor_test() + + +@image_comparison(baseline_images=['fancyarrow_dpi_cor_200dpi'], + remove_text=True, extensions=['png'], + savefig_kwarg=dict(dpi=200)) +def test_fancyarrow_dpi_cor_200dpi(): + """ + As test_fancyarrow_dpi_cor_100dpi, but exports @ 200 DPI. The relative size + of the arrow head should be the same. + """ + + __prepare_fancyarrow_dpi_cor_test() + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 99fbe424892b..92d3f067a525 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -2147,7 +2147,6 @@ def _update_position_xytext(self, renderer, xy_pixel): d = self.arrowprops.copy() ms = d.pop("mutation_scale", self.get_size()) - ms = renderer.points_to_pixels(ms) self.arrow_patch.set_mutation_scale(ms) if "arrowstyle" not in d: @@ -2164,11 +2163,10 @@ def _update_position_xytext(self, renderer, xy_pixel): " use 'headlength' to set the head length in points.") headlength = d.pop('headlength', 12) - to_style = self.figure.dpi / (72 * ms) - - stylekw = dict(head_length=headlength * to_style, - head_width=headwidth * to_style, - tail_width=width * to_style) + # NB: ms is in pts + stylekw = dict(head_length=headlength / ms, + head_width=headwidth / ms, + tail_width=width / ms) self.arrow_patch.set_arrowstyle('simple', **stylekw)