Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty scatter messes up the limits #1490

Closed
akhmerov opened this issue Nov 13, 2012 · 3 comments · Fixed by #1497
Closed

empty scatter messes up the limits #1490

akhmerov opened this issue Nov 13, 2012 · 3 comments · Fixed by #1497

Comments

@akhmerov
Copy link
Contributor

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()

@WeatherGod
Copy link
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().

@akhmerov
Copy link
Contributor Author

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

@efiring
Copy link
Member

efiring commented Feb 17, 2013

Closed by #1497

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

Successfully merging a pull request may close this issue.

3 participants