diff --git a/doc/api/api_changes.rst b/doc/api/api_changes.rst index 0ed2dd87a796..98aa4873605a 100644 --- a/doc/api/api_changes.rst +++ b/doc/api/api_changes.rst @@ -15,6 +15,10 @@ For new features that were added to matplotlib, please see Changes in 1.3.x ================ +* Fixed a bug in setting the position for the right/top spine with data + position type. Previously, it would draw the right or top spine at + +1 data offset. + * In :class:`~matplotlib.patches.FancyArrow`, the default arrow head width, ``head_width``, has been made larger to produce a visible arrow head. The new value of this kwarg is ``head_width = 20 * width``. diff --git a/lib/matplotlib/spines.py b/lib/matplotlib/spines.py index 55bc58462e1f..d0b7a26d1dfa 100644 --- a/lib/matplotlib/spines.py +++ b/lib/matplotlib/spines.py @@ -323,6 +323,11 @@ def _calc_offset_transform(self): self._spine_transform = ('identity', mtransforms.IdentityTransform()) elif position_type == 'data': + if self.spine_type in ('right', 'top'): + # The right and top spines have a default position of 1 in + # axes coordinates. When specifying the position in data + # coordinates, we need to calculate the position relative to 0. + amount -= 1 if self.spine_type in ('left', 'right'): self._spine_transform = ('data', mtransforms.Affine2D().translate( diff --git a/lib/matplotlib/tests/baseline_images/test_spines/spines_data_positions.pdf b/lib/matplotlib/tests/baseline_images/test_spines/spines_data_positions.pdf new file mode 100644 index 000000000000..38355c76df3c Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_spines/spines_data_positions.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_spines/spines_data_positions.png b/lib/matplotlib/tests/baseline_images/test_spines/spines_data_positions.png new file mode 100644 index 000000000000..024b243fa59a Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_spines/spines_data_positions.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_spines/spines_data_positions.svg b/lib/matplotlib/tests/baseline_images/test_spines/spines_data_positions.svg new file mode 100644 index 000000000000..5cfd7b161136 --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_spines/spines_data_positions.svg @@ -0,0 +1,544 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_spines.py b/lib/matplotlib/tests/test_spines.py index 9674215dac99..82046706af55 100644 --- a/lib/matplotlib/tests/test_spines.py +++ b/lib/matplotlib/tests/test_spines.py @@ -19,3 +19,14 @@ def test_spines_axes_positions(): ax.xaxis.set_ticks_position('top') ax.spines['left'].set_color('none') ax.spines['bottom'].set_color('none') + +@image_comparison(baseline_images=['spines_data_positions']) +def test_spines_data_positions(): + fig = plt.figure() + ax = fig.add_subplot(1,1,1) + ax.spines['left'].set_position(('data', -1.5)) + ax.spines['top'].set_position(('data', 0.5)) + ax.spines['right'].set_position(('data', -0.5)) + ax.spines['bottom'].set_position('zero') + ax.set_xlim([-2,2]) + ax.set_ylim([-2,2]) \ No newline at end of file