You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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()
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.
Activity
WeatherGod commentedon Nov 13, 2012
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 commentedon Nov 14, 2012
@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 withadd_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 throughpath.get_path_collection_extents. This function, in turn calls_path.get_path_collection_extents. That function, when provided withoffsets=[]treats the offsets as if they were[0, 0](this behavior is used inpath.get_paths_extents).The proper fix, as far as I can tell, would be to correct
_path.get_path_collection_extents, such that it returnsNone's ifoffsets=[], and to call it withoffsets=[0, 0]frompath.get_paths_extents. I am not sure whetherNone'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_collectionadding 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 forpath.get_path_collection_extents.efiring commentedon Feb 17, 2013
Closed by #1497