Skip to content

empty scatter messes up the limits #1490

Closed

Description

@akhmerov

Tested with 1.1.1 (didn't manage 1.2.0 to show anything yet).

To reproduce:

from matplotlib import pyplot as plt
plt.scatter([0,1],[0,1])
plt.scatter([], []) # The lower limit shifts appreciably, compared to not executing this line.
plt.show()

Activity

  1. WeatherGod commented on Nov 13, 2012

    @WeatherGod
    Member

    Confirmed. Furthermore, it should be noted that each subsequent call to empty scatter will grow the limits even further. I suspect it is some sort of issue with autoscale_view() when one has an empty collection. A temporary fix would be to only call autoscale_view() if the length of the collection is greater than zero, but I would rather fix the issue with autoscale_view().

  2. akhmerov commented on Nov 14, 2012

    @akhmerov
    ContributorAuthor

    @WeatherGod I found the problem, and the issue is not with autoscale_view(). What happens instead is that an empty collection with a set path has non-empty datalimits, so when it is added with add_collection, the datalimits aren't updated correctly (that is they do actually become modified and don't stay the same). The collection datalimits are obtained through path.get_path_collection_extents. This function, in turn calls _path.get_path_collection_extents. That function, when provided with offsets=[] treats the offsets as if they were [0, 0] (this behavior is used in path.get_paths_extents).

    The proper fix, as far as I can tell, would be to correct _path.get_path_collection_extents, such that it returns None's if offsets=[], and to call it with offsets=[0, 0] from path.get_paths_extents. I am not sure whether None's would be a legitimate value of datalimits, but the behavior that I described would at least be logical.

    Another fix, which doesn't prevent this issue from popping up somewhere else would be to fix axes.add_collection adding an extra check for offsets. I will submit a pull request with this fix shortly, and if it's accepted I recommend to open an extra issue for path.get_path_collection_extents.

  3. efiring commented on Feb 17, 2013

    @efiring
    Member

    Closed by #1497

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