Skip to content

Right and top spine placement: set_position(('data', x)) puts the spine at x + 1 instead of x. #1960

Closed

Description

@technobauble

Python Version 2.7.4
matplotlib version: 1.1.1

Setting the location of the top and right spines to X is locating them at X +1. The left and bottom spines are placed as expected.

I posted this to the users list and it was verified by Goyo goyodiaz@gmail.com.

The following code demonstrates the error:

import matplotlib.pyplot as plt

f=plt.figure(1)
f.clf()
ax=plt.subplot(111)

# spine is located at x = -1.5
ax.spines['left'].set_position(('data', -1.5)) 

# spine should be located at y = 0.5 but is placed at y = 1.5
ax.spines['top'].set_position(('data',0.5)) 

# spine should be located at x = -0.5 but is placed at x = +0.5
ax.spines['right'].set_position(('data',-0.5))

# spine is placed at y = 0.
ax.spines['bottom'].set_position('zero')

ax.set_xlim([-2,2])
ax.set_ylim([-2,2])

plt.show()

Activity

  1. cimarronm commented on Apr 30, 2013

    @cimarronm
    Contributor

    The issue is coming because right and top splines are initialized with a path vertex of 1 instead of zero as follows (the 13 is a placeholder that is replaced when _adjust_location is called before drawing the spine):

           if spine_type == 'left':
                path = mpath.Path([(0.0, 13), (0.0, 13)])
            elif spine_type == 'right':
                path = mpath.Path([(1.0, 13), (1.0, 13)])
            elif spine_type == 'bottom':
                path = mpath.Path([(13, 0.0), (13, 0.0)])
            elif spine_type == 'top':
                path = mpath.Path([(13, 1.0), (13, 1.0)])

    Then when the affine spine transform is set it is offsets it by the amount you give. It seems to me the proper solution is to adjust the spine transform to handle right and top differently than left and bottom when the requested position is data offset. I have a patch for it and testcase ready if that is the way we want to go.

  2. added a commit that references this issue on Apr 30, 2013
  3. added a commit that references this issue on May 11, 2013
  4. dmcdougall commented on Jun 16, 2013

    @dmcdougall
    Member

    Fixed by #1964 so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions