empty scatter messes up the limits #1490

akhmerov opened this Issue Nov 13, 2012 · 3 comments

3 participants


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([], []) # The lower limit shifts appreciably, compared to not executing this line.

Matplotlib Developers 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().


@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.

Matplotlib Developers member

Closed by #1497

@efiring efiring closed this Feb 17, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment