Addresses issue #23129: Fixed log scale order dependency when using Collections #28021
+24
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR attempts to resolve issue #23129, in which there is an order dependency when using logaritmic scales and a
Collection
as data.PR summary
Error Description
The error in axis computation originates from the
add_collection()
method within the_AxesBase
class (found in lib/matplotlib/axes/_base.py). Specifically, the issue lies in how the axis limits are computed.Analysis
Further investigation into the
get_datalim()
method in theCollection
class (lib/matplotlib/collections.py) reveals that data limits are influenced by a non-affine transformation:In scenarios where the axis scale is set after adding the data collection, and so the log scale is not yet applied, the data limits are computed as if the data were affine, and yet the correct behavior is achieved. In other words, the shape of the data should not impact bounding limit computation. Therefore, the non-affine transformation is not only unnecessary but also detrimental, as it produces inaccurate results, and its removal solves the issue.
Unit Test
Finnaly, a unit test was added,
test_collection_log_datalim_order_dependency()
(to lib/matplotlib/tests/test_collections.py), which validates the order dependency, ensuring the correctness of the fix.PR checklist